帝国cms用自定义标签函数任意位置循环调用tags标签


包括首页/列表页/内容页都可以用这个方法

帝国CMS想要在各个页面显示TAG标签,网上已经有很多教程,不过大部分人给的方法都是直接在模板里写一堆代码,今天就整理下写成函数,这样调用起来会更方便、

只需要将代码添加到userfun.php中:

function taglinks($aid, $num=3, $tbname='news'){ global $public_r,$dbtbpre,$empire,$navinfor,$class_r; $qr = $empire->fetch1("select rewritetags from {$dbtbpre}enewspublic limit 1"); $sr = $empire->fetch1("select stb from {$dbtbpre}ecms_{$tbname} where id=$aid"); $fr = $empire->fetch1("select infotags from {$dbtbpre}ecms_{$tbname}_data_{$sr[stb]} where id=$aid"); $tagstr = ''.$fr[infotags].''; $tagarr = explode(",", $tagstr); for($i=0; $i<count($tagarr) && $i<$num; $i++) { if($tagarr[$i]){ $tr = $empire->fetch1("select * from {$dbtbpre}enewstags where tagname='".$tagarr[$i]."'"); if($qr[rewritetags]) { // 开启伪静态 $link = "/tag".$tr[tagid]."/"; } else { // 动态链接 $link = "/tag/".$tr[tagid]."/"; } $tags .= "<a href='$link' target='_blank'>".$tagarr[$i]."</a>";} } return $tags;}

参数:文章ID,调用标签数量,表名
灵动标签调用

<?=taglinks($bqr[id])?>

列表页,勾选list.var使用程序代码,代码示例

$listtemp='<li> <h3><a href="[!--titleurl--]">[!--title--]</a></h3> <p>[!--smalltext--]</p> <p>'.taglinks($r[id]).'</p></li>';

内容页调用

<?=taglinks($navinfor[id])?>

上一篇:帝国cms用php的方式输出序列号数组方法

下一篇:帝国CMS 启用https后台登录空白处理方法


函数 TAG标签
Copyright © 2002-2019 测速网 https://www.inhv.cn/ 皖ICP备2023010105号 城市 地区 街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!
热门搜索