【实测】discuz标签聚合页调用tag标签和相关帖子数量及排序方法

来自版块 Discuz教程
287
0
温馨提示:如下载链接失效,请前往 问题反馈专用帖 进行反馈! 兔源码交流群:493651246

演示地址:https://www.tuyuanma.com/tag.html

找到标签显示页,修改更换如下代码
  1. <!--{eval $mtags = DB::fetch_all("SELECT a.tagid, a.tagname, count(b.tagid) as tag_count FROM ".DB::table("common_tag")." a LEFT JOIN ".DB::table("common_tagitem")." b on b.tagid=a.tagid WHERE a.`status` = 0 group by b.tagid ORDER BY a.`tagid` DESC LIMIT 0,480");}-->
  2. <div class="fmtags">
  3. <!--{loop $mtags $mtag}-->
  4. <!--{if $mtag[tag_count]>0}-->
  5. <a href="misc.php?mod=tag&id=$mtag[tagid]" target="_blank" class="xi2">$mtag[tagname]{$mtag[tag_count]}</a>
  6. <!--{/if}-->
  7. <!--{/loop}-->
  8. </div>
复制代码
其中DESC为按升序排序,如需按降序排序,则修改为ASC即可
按标签相关帖子数排序代码
  1. <!--{eval $mtags = DB::fetch_all("SELECT a.tagid, a.tagname, count(b.tagid) as tag_count FROM ".DB::table("common_tag")." a LEFT JOIN ".DB::table("common_tagitem")." b on b.tagid=a.tagid WHERE a.`status` = 0 group by b.tagid ORDER BY `tag_count` DESC LIMIT 0,480");}-->
  2. <div class="fmtags">
  3. <!--{loop $mtags $mtag}-->
  4. <!--{if $mtag[tag_count]>0}-->
  5. <a href="misc.php?mod=tag&id=$mtag[tagid]" target="_blank" class="xi2">$mtag[tagname]{$mtag[tag_count]}</a>
  6. <!--{/if}-->
  7. <!--{/loop}-->
  8. </div>
复制代码
简单描述:
查询tag的两个表common_tag和common_tagitem,获取tagid,tagname两个字段,并统计tagid个数,分组合计,按tagid倒序排序,取前480条

全部评论 0

您需要登录后才可以回帖 立即登录
输入你要评论的内容......
0
0
0
返回顶部