调用信息的TAG
1、调用信息TAG的函数,放进 e/class/userfun.php 文件 ?> 代码之前,方便在模板中调用
/*** $classid 信息栏目id $id 信息id $exp 包裹每一个tag的前后标签,用|分割,默认是<li><a href="">TAG</a></li> $limit 调用tag数量,默认10个 ***/ function dp_InfoTag($classid,$id,$exp="<li>|</li>",$limit=10){ global $dbtbpre,$empire,$public_r; $tagstr=''; $i=0; $q=explode("|",$exp); $tsql=$empire->query("select tagid from {$dbtbpre}enewstagsdata where id=".$id." and classid=".$classid.""); while($tr=$empire->fetch($tsql)){ $tt=$empire->fetch1("select * from {$dbtbpre}enewstags where tagid=".$tr['tagid']." limit 1"); if($tt['tagid']){ if($i>$limit&&$limit){ break; } $tagurl=dp_itagLink($tr['tagid']); $tagstr.=$q[0].'<a href="'.$tagurl.'" title="'.$tt['tagname'].'" class="c1" target="_blank">'.$tt['tagname'].'</a>'.$q[1]; $i+=1; } } return $tagstr; } |
2、在内容页模板中使用上述dp_InfoTag函数,调用当前信息的tag
<?=dp_InfoTag($navinfor['classid'],$navinfor['id'],'|<br>',8)?> |
3、在列表页中,列表内容模板(list.var) 使用dp_InfoTag函数的例子:
$tagstr=dp_InfoTag($r['classid'],$r['id'],'| ',5); $listtemp=' <li> <h3><a href="[!--titleurl--]">[!--title--]</a></h3> <p>[!--smalltext--]</p> TAG:'.$tagstr.' </li> '; |
注意需要勾选使用程序代码。帝国CMS官网:list.var使用程序代码说明
4、灵动标签中使用dp_InfoTag函数的例子:
[e:loop={灵动标签调用语句}] <? $thistagstr=dp_InfoTag($bqr['classid'],$bqr['id'],'| ',10); ?> <a href="" target="_blank"></a> TAG: <?=$thistagstr?> [/e:loop] |
调用多个TAG
1、调用最新10个tag
<? $tsql=$empire->query("select * from {$dbtbpre}enewstags order by tagid desc limit 10"); while($tr=$empire->fetch($tsql)){ $tagurl=dp_itagLink($tr['tagid']); ?> <li><a href=""><?=$tr['tagname']?></a>(<?=$tr['num']?>)</li> <?}?> |
2、按分类调用TAG
<? $tcsql=$empire->query("select * from {$dbtbpre}enewstagsclass where classid>0 order by classid desc"); while($tcr=$empire->fetch($tcsql)){ $tagclassurl=dp_itagClassLink($tcr['classid']); ?> <div class="showtag"> <h3><a href="<?=$tagclassurl?>"><?=$tcr['classname']?></a></h3> <ul> <? $tsql=$empire->query("select * from {$dbtbpre}enewstags where cid=".$tcr['classid']." order by tagid desc limit 10"); while($tr=$empire->fetch($tsql)){ $tagurl=dp_itagLink($tr['tagid']); ?> <li><a href="<?=$tagurl?>"><?=$tr['tagname']?></a>(<?=$tr['num']?>)</li> <? } ?> </ul> </div> <? } ?> |
3、按照tag拼音字母顺序调用
<?php $zm_r=array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'); ?> <div class="zmlist"> 字母: <? foreach($zm_r as $zm){ ?> <a href="#<?=$zm?>"><?=strtoupper($zm)?></a> <? } ?> </div> <div class="taglist"> <? foreach($zm_r as $zm){ ?> <h3><a name="<?=$zm?>"><?=strtoupper($zm)?></a></h3> <ul> <? $zsql=$empire->query("select tagid from {$dbtbpre}dp_tagsadd where py like '".$zm."%' order by tagid desc"); while($zr=$empire->fetch($zsql)){ $t=$empire->fetch1("select * from {$dbtbpre}enewstags where tagid='$zr[tagid]' limit 1"); $tagurl=dp_itagLink($zr[tagid]); ?> <li><a href="<?=$tagurl?>"><?=$t['tagname']?></a></li> <? } ?> </ul> <? } ?> </div> |
4、在栏目页模板,根据tag分类绑定的栏目,调用此栏目下的TAG
<?php $bdsql=$empire->query("select * from {$dbtbpre}dp_itag_class where modid='$navclassid'"); while($bdr=$empire->fetch($bdsql)){ $cid=$bdr['classid']; $tcsql=$empire->query("select * from {$dbtbpre}enewstagsclass where classid='$cid' order by classid desc"); while($tcr=$empire->fetch($tcsql)){ $tagclassurl=dp_itagClassLink($tcr['classid']); ?> <div class="showtag"> <h3><a href="<?=$tagclassurl?>"><?=$tcr['classname']?></a></h3> <ul> <? $tsql=$empire->query("select * from {$dbtbpre}enewstags where cid=".$tcr['classid']." order by tagid desc limit 10"); while($tr=$empire->fetch($tsql)){ $tagurl=dp_itagLink($tr['tagid']); ?> <li><a href="<?=$tagurl?>"><?=$tr['tagname']?></a>(<?=$tr['num']?>)</li> <? } ?> </ul> </div> <? } } ?> |