比喻站点的最新公告显示位就没有,在网上找了好久,没有发现相关的信息,可能是我没有找到,所以就花了几个小时研究了一下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" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="https://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;