论坛里给的方法都是直接在模板里写一堆代码,整理下写成函数,调用起来更方便。
将代码添加到userfun.php中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | function taglinks( $aid , $num =5, $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 ]) { if ( $qr [rewritetags]) { // 开启<a href="http://www.11px.cn/tags/wjt/" target="_blank">伪静态</a> $link = $public_r [newsurl]. "tags-" .urlencode( $tagarr [ $i ]). "-0.html" ; } else { // 动态链接 $link = $public_r [newsurl]. "e/tags/?tagname=" .urlencode( $tagarr [ $i ]); } $tags .= "<a href='$link' target='_blank'>" . $tagarr [ $i ]. "</a> " ; } } return $tags ; } ?> |
有朋友需要调用tagid形式的,再查次数据库就可以了
以下代码修改下
1 2 3 4 5 6 7 8 9 | if ( $tagarr [ $i ]) { if ( $qr [rewritetags]) { // 开启<a href="http://www.11px.cn/tags/wjt/" target="_blank">伪静态</a> $link = $public_r [newsurl]. "tags-" .urlencode( $tagarr [ $i ]). "-0.html" ; } else { // 动态链接 $link = $public_r [newsurl]. "e/tags/?tagname=" .urlencode( $tagarr [ $i ]); } $tags .= "<a href='$link' target='_blank'>" . $tagarr [ $i ]. "</a> " ; } |
修改后:
1 2 3 4 5 6 7 8 9 10 | if ( $tagarr [ $i ]) { $tr = $empire ->fetch1( "select * from {$dbtbpre}enewstags where tagname='" . $tagarr [ $i ]. "'" ); if ( $qr [rewritetags]) { // 开启伪静态 $link = $public_r [newsurl]. "tags-etagid" . $tr [tagid]. "-0.html" ; } else { // 动态链接 $link = $public_r [newsurl]. "e/tags/?tagid=" . $tr [tagid]; } $tags .= "<a href='$link' target='_blank'>" . $tagarr [ $i ]. "</a> " ; } |
参数:文章ID,调用标签数量,表名
灵动标签调用:<?=taglinks($bqr[id])?>
列表页,勾选list.var使用程序代码,代码示例
1 2 3 4 5 6 7 | $listtemp =' <li> <h3><a href= "[!--titleurl--]" >[!--title--]</a></h3> <p>[!--smalltext--]</p> <p> '.taglinks($r[id]).' </p> </li> '; |
内容页调用:<?=taglinks($navinfor[id])?>
新闻热点
疑难解答