总结为4种方法:
用法1、
[e:loop={"select DISTINCT([!db.pre!]enewstags.tagname),[!db.pre!]enewstags.tagid,[!db.pre!]enewstags.num from [!db.pre!]enewstags inner join [!db.pre!]enewstagsdata on [!db.pre!]enewstags.tagid = [!db.pre!]enewstagsdata.tagid where [!db.pre!]enewstagsdata.classid = 25 order by [!db.pre!]enewstags.num DESC limit 30",0,24}]
<a href='<?=$public_r['newsurl']?>e/tags/?tagname=<?=$bqr['tagname']?>' title='<?=$bqr['num']?>个'><?=$bqr['tagname']?>(<?=$bqr['num']?>)</a>
[/e:loop]
用法2、(和上面的相同,只是sql格式有稍微不同)
[e:loop={"select a.tagname,a.num,b.tagid from [!db.pre!]enewstags a,[!db.pre!]enewstagsdata b where a.tagid=b.tagid and classid=34 group by tagid order by num desc limit 40",40,24,0}]
<a href='<?=$public_r['newsurl']?>e/tags/?tagname=<?=$bqr['tagname']?>' title='<?=$bqr['num']?>个'><?=$bqr['tagname']?>(<?=$bqr['num']?>)</a>
[/e:loop]
用法3、(和上面的相同,只是sql格式有稍微不同)
[e:loop={"select a.*,b.* from [!db.pre!]enewstags a,[!db.pre!]enewstagsdata b where a.tagid=b.tagid and classid=25 group by b.tagid order by a.num desc limit 40",40,24,0}]
<a href='<?=$public_r['newsurl']?>e/tags/?tagname=<?=$bqr['tagname']?>' title='<?=$bqr['num']?>个'><?=$bqr['tagname']?>(<?=$bqr['num']?>)</a>
[/e:loop]
用法4、(和上面的相同,只是sql格式有稍微不同)
[e:loop={"select a.*,b.* from [!db.pre!]enewstags a LEFT JOIN [!db.pre!]enewstagsdata b ON a.tagid=b.tagid where classid=25 group by b.tagid order by a.num desc limit 100",0,24,0}]
<a href='<?=$public_r['newsurl']?>e/tags/?tagname=<?=$bqr['tagname']?>' title='<?=$bqr['num']?>个'><?=$bqr['tagname']?>(<?=$bqr['num']?>)</a>
[/e:loop]
注释:classid = 25 为栏目ID必须为终极栏目
注意当tag数据很多的时候使用此方法会比较消耗系统资源,应视情况少用或优化使用。
1、上面的为调用单个栏目
2、多个栏目时,修改classid = 25 为 classid in(25,35,36,37)
3、调用当前栏目(列表、内容通用):把 classid = 25 替换为 classid='$GLOBALS[navclassid]'
本文摘自网络,不代表短经典网立场 https://www.duanjingdian.com/602.html