最近在做一个网站用到副栏目的调用,在网上搜了一下,没有找到一个好的方法,于是自己写了一个,希望能够帮到大家。
方法一:内容页的调用写法:{dede:field.typeid2 runphp='yes'} global $dsql; $ks = split(',', @me); $tname=""; foreach($ks as $k){ $k = trim($k); if ($k!="") { if ($row = $dsql->getOne("select *,ID as id1 from dede_arctype where id=".$k)){$mpath=GetTypeUrl($row['id1'],MfTypedir($row['typedir']),$row['isdefault'],$row['defaultname'],$row['ispart'],$row['namerule2'],$row['siteurl']); $tname.="<span><a href='{$mpath}'>".$row['typename']."</a></span>"; } } } @me=substr($tname,0,strlen($tname)-1); {/dede:field.typeid2首页、列表页标签(在arclist、list等文章列表标签里用): [field:typeid2 runphp='yes'] global $dsql; $ks = split(',', @me); $tname=""; foreach($ks as $k){ $k = trim($k); if ($k!="") { if ($row = $dsql->getOne("select *,ID as id1 from dede_arctype where id=".$k)){ $mpath=GetTypeUrl($row['id1'],MfTypedir($row['typedir']),$row['isdefault'],$row['defaultname'],$row['ispart'],$row['namerule2'],$row['siteurl']); $tname.="<span><a href='{$mpath}'>".$row['typename']."</a></span>"; } } } @me=substr($tname,0,strlen($tname)-1); [/field:typeid2]推荐用这种方法,不需要改东西就可以了。另外在网上看到另外一种方法,不过我没做测试,有兴趣的朋友可以试下。
方法二:首先在 dedecms 目录下 /plus/ 新建文件 type_ajax.php 内容如下:<?phprequire_once(dirname(__FILE__)."/../include/common.inc.php");$action = isset($action) ? trim($action) : '';$id = (isset($id) && is_numeric($id)) ? $id : 0;if($id < 1){exit();}$maintable = "dede_archives";$digg = '';$row = $dsql->GetOne("Select * From dede_archives where id = '$id' ");$arr = split(",",$row['typeid2']);foreach ($arr as $key=>$type){$namelist = $dsql->GetOne("Select * From dede_arctype where id = '$type' ");$digg .= '<a href=/plus/list.php?tid='.$type.'>'.$namelist['typename'].'<a>'." //";}AjaxHead();echo $digg;exit();?>dedecms 模板页调用在<head>标记之间 加上 <script language="javascript" type="text/javascript" src="{dede:global.cfg_cmsurl/}/include/dedeajax2.js"></script><script language="javascript" type="text/javascript"><!--function gettype(aid)