比喻站點的最新公告顯示位就沒有,在網上找了好久,沒有發現相關的信息,可能是我沒有找到,所以就花了幾個小時研究了一下DEDECMS的部分源碼,試想,何不自已寫呢好吧,想法有了,開始形動吧,跟我來,讓狼人教你DIY一個自定義的模塊.在這里我就給大家舉一個實例<<站點公告信息的模板>>主要有:<<首頁顯示最新公告>>,<<公告詳細顯示頁面>>,<<公告列表頁面>>好的,我們一個個的來一.<<首頁顯示最新公告>>首先是在首頁顯示最新公告<在index.htm頁面添加代碼>代碼標簽是:begin:{dede:mynews row='1' titlelen='20'}最新公告:[field:title /]<a href="show-mynews.php?aid=[field:aid /]">查看詳細</a></div>{/dede:mynews}end;
<<公告詳細顯示頁面>>新建文件show-mynews.php代碼如下:----------begin:<?phprequire_once (dirname(__FILE__) . "/include/common.inc.php");require_once DEDEINC."/arc.partview.class.php";?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>公告詳細</title><link href="/templets/style/dedecms.css" rel="stylesheet" media="screen" type="text/css" /><script language="javascript" type="text/javascript" src="/include/dedeajax2.js"></script><script src="/js/jquery-1.2.6.min.js" language="javascript" type="text/javascript"></script></head><body><?php$pv = new PartView();$pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/default/head.htm");$pv->Display();?><?phpif (! is_numeric($aid)){echo "瀏覽頁面參數不正確";exit;}global $dsql;$row = $dsql->GetOne("Select * from dede_mynews where aid=$aid");if(!is_array($row)){echo "對不起,沒有找到您所查找到的公告信息";exit;}?><div class="w960 center" style="border:#ccc 1px solid;margin-top:5px;"><?phpecho "<h1 style='text-align:center;margin-top:20px;font-size:20px;border-bottom:#ccc 1px solid;'>".$row["title"]."</h1>";echo "<div style='padding:8px;'>".$row["body"]."</div>";?></div><?php$pv = new PartView();$pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/default/footer.htm");$pv->Display();?></body></html>end;
<<公告列表頁面>>改顯示所有公告列表,不分頁<公告本來就不是很多所以這里我們不分頁顯示列表了>在include aglib目錄下面找到文件(mynews.lib.php)代碼標簽是:begin:<?phpfunction lib_mynews(&$ctag,&$refObj){global $dsql,$envs;//屬性處理$attlist="row|1,titlelen|24";FillAttsDefault($ctag->CAttribute->Items,$attlist);extract($ctag->CAttribute->Items, EXTR_SKIP);$innertext = trim($ctag->GetInnerText());if(empty($row)) $row=1;if(empty($titlelen)) $titlelen=30;if(empty($innertext)) $innertext = GetSysTemplets('mynews.htm');$idsql = '';if($envs['typeid'] > 0) $idsql = " where typeid='".GetTopid($this->TypeID)."' ";$dsql->SetQuery("Select * from dede_mynews $idsql order by senddate desc limit 0,$row");if($row == -1) $dsql->SetQuery("Select * from dede_mynews $idsql order by senddate desc");//狼人(QQ:459094521)加,如果設置為-1,就顯示所有文章$dsql->Execute();$ctp = new DedeTagParse();$ctp->SetNameSpace('field','[',']');$ctp->LoadSource($innertext);$revalue = '';while($row = $dsql->GetArray()){foreach($ctp->CTags as $tagid=>$ctag){@$ctp->Assign($tagid,$row[$ctag->GetName()]);}$revalue .= $ctp->GetResult();}return $revalue;}?>end;在站點根目錄新建list-mynews.php里面寫代碼:begin:/*用于調用/default/list-mynews.htm頁面的標簽來顯示*/<?phprequire_once (dirname(__FILE__) . "/include/common.inc.php");require_once DEDEINC."/arc.partview.class.php";$pv = new PartView();$pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/default/list-mynews.htm");$pv->Display();?>end;在templetsdefault目錄下面新建文件list-mynews.htm,并寫代碼如下:begin:{dede:mynews row='-1' titlelen='20'}<br/>編號:[field:aid /],<a href='show-mynews.php?aid=[field:aid /]'>標題:[field:title /]</a>,作者:[field:writer /],發布時間:[field:senddate /],內容:[field:body /]<br/>{/dede:mynews}end;