帝国CMS模板调用指定栏目的tag或当前栏目的tag

COS、CDN

在帝国CMS模板中,可以通过不同的SQL查询方式来调用指定栏目中的所有TAG。以下是四种不同的方法及其解释。

方法1

SQL 查询

sql
 
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 = 34 order by [!db.pre!]enewstags.num DESC limit 30

模板代码

html
 
[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 = 34 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 查询

sql
 
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

模板代码

html
 
[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 查询

sql
 
select a.*, b.* from [!db.pre!]enewstags a, [!db.pre!]enewstagsdata b where a.tagid = b.tagid and classid = 34 group by b.tagid order by a.num desc limit 40

模板代码

html
 
[e:loop={"select a.*, b.* from [!db.pre!]enewstags a, [!db.pre!]enewstagsdata b where a.tagid = b.tagid and classid = 34 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 查询

sql
 
select a.*, b.* from [!db.pre!]enewstags a LEFT JOIN [!db.pre!]enewstagsdata b ON a.tagid = b.tagid where classid = 34 group by b.tagid order by a.num desc limit 100

模板代码

html
 
[e:loop={"select a.*, b.* from [!db.pre!]enewstags a LEFT JOIN [!db.pre!]enewstagsdata b ON a.tagid = b.tagid where classid = 34 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]

注释

  1. 调用单个栏目

    • 将 classid = 34 替换为你需要的栏目 ID。
  2. 多个栏目时

    • 将 classid = 34 替换为 classid in(34, 35, 36, 37)
  3. 调用当前栏目

    • 将 classid = 34 替换为 classid = '$GLOBALS[navclassid]'

总结

以上四种方法都可以实现调用指定栏目中的所有 TAG。根据实际需求选择合适的方法,并根据需要调整 SQL 查询中的条件。

COS、CDN
热门