dedecms专题模板应用分析及解决方案
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>无柰只有靠自己动手丰衣足食;在官方的版本上有这样的一段话: <br>
1、文章列表用ID1,ID2,ID3这样形式分开,系统会自动排除不同节点的相同文章;<br>
2、关于单条记录模板里的标记的使用,请参考关于系统帮助关于 arclist 标记的说明;<br>
3、节点ID是节点的唯一标识,允许在专题模板中用{dede:specnote id='标识'/}这样来表示单个节点。<br>
4、正常的情况下,每个节点显示的是“节点文章列表”里的文档,如果你指定为“自动获取模式”,那么必须指定关键字和栏目ID。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
可是经测试{dede:specnote id='标识'/}这个并没有升效;因此开始解决这个,以替换掉原来比较死板{dede:field name='note'/}标签;</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
举例说明:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
我要分两栏显示不同节点的文章,目前用"note"就不能实现,只能是同一节点分栏,难免就显得有些捌扭,不够灵活。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
下面我就把自己解决方案写下供同学们参考,首先得申明一点,只能是实现了功能,可算法不一定是最好的,因为我不太熟悉DEDECMS代码且没有认真的研究过,希望大家海涵!</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
步骤1:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
文件位置:{include/inc_archives_view.php} <br>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode3" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
//广告标记<br>
//-----------------------<br>
else if($ctag->GetName()=="myad"){<br>
$this->dtp->Assign($tagid,$this->PartView->GetMyAd($typeid,$ctag->GetAtt("name")));<br>
}<br>
// 专题标识<br>
// by phpfans<br>
else if($ctag->GetName()=="specnote"){<br>
$this->dtp->Assign($tagid,$this->ChannelUnit->GetSpecList('',$this->ChannelUnit->specrule,$ctag->GetAtt("id")));<br>
}</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
介绍:{在广告标记下增加专题标识}这样专题文章列表页就可以识别specnote标签了</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
步骤2:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
文件位置:{include/inc_channel_unit.php} <br>
var $specrule;<br>
//-------------<br>
//php5构造函数<br>
//-------------</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
介绍:增加了对$pecrule变量的定义</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
步骤3:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
文件位置:{include/inc_channel_unit.php} <br>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode4" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
else if($ftype=="specialtopic"){<br>
$this->specrule = $fvalue;<br>
$fvalue = $this->GetSpecList($fname,$fvalue); <br>
}</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
介绍:这儿增加了$this->specrule = $fvalue;这句,以便获取addonspec表的note字段数据;</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
步骤4:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
文件位置:{include/inc_channel_unit.php} <br>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode5" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
//获得专题文章的列表<br>
//--------------------------------<br>
function GetSpecList($fname,$noteinfo,$noteid="")<br>
{<br>
if(!isset($GLOBALS['__SpGetArcList'])) require_once(dirname(__FILE__)."/inc/inc_fun_SpGetArcList.php");<br>
if($noteinfo=="") return "";<br>
$rvalue = "";<br>
$tempStr = GetSysTemplets("channel/channel_spec_note.htm");<br>
$dtp = new DedeTagParse(); </p> <p></p> <p>$dtp->LoadSource($noteinfo);<br>
if(is_array($dtp->CTags))<br>
{<br>
foreach($dtp->CTags as $k=>$ctag){<br>
$notename = $ctag->GetAtt("name");<br>
if($noteid!="" && $ctag->GetAtt("noteid")!=$noteid){ continue; } //指定名称的专题节点<br>
if($noteid!="" && $ctag->GetAtt("noteid")===$noteid) {<br>
$isauto = $ctag->GetAtt("isauto");<br>
$idlist = trim($ctag->GetAtt("idlist"));<br>
$rownum = trim($ctag->GetAtt("rownum"));<br>
if(empty($rownum)) $rownum = 40;<br>
$keywords = "";<br>
$stypeid = 0;</p> <p>if($isauto==1){<br>
$idlist = "";<br>
$keywords = trim($ctag->GetAtt("keywords"));<br>
$stypeid = $ctag->GetAtt("typeid");<br>
}</p> <p>if(trim($ctag->GetInnerText())!="") $listTemplet = $ctag->GetInnerText();<br>
else $listTemplet = GetSysTemplets("spec_arclist.htm");<br>
$idvalue = SpGetArcList($this->dsql,<br>
$stypeid,$rownum,$ctag->GetAtt("col"),<br>
$ctag->GetAtt("titlelen"),$ctag->GetAtt("infolen"),<br>
$ctag->GetAtt("imgwidth"),$ctag->GetAtt("imgheight"),<br>
"all","default",$keywords,$listTemplet,100,0,$idlist);</p> <p>$notestr = str_replace("~notename~",$notename,$tempStr);<br>
$notestr = str_replace("~spec_arclist~",$idvalue,$notestr);<br>
$rvalue .= $notestr;<br>
if($noteid!="" && $ctag->GetAtt("noteid")==$noteid){ break; }<br>
}<br>
}<br>
}<br>
$dtp->Clear();<br>
return $rvalue;<br>
}</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
介绍:有些小改动,自己对比一下就清楚了,这儿就不再哆嗦了</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
步骤5:<br>
说明: 原{dede:field name='note'/}标签失效了,如果要用的朋友请自行修改步骤四部份。。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
很简单的;</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
完工!</p>
頁:
[1]