# 帝国cms二次开发如何统计专题信息数量

*Published:* 2023-12-16
*Author:* 客服001

#### 温馨提醒

如果文章内容或图片资源失效，请留言反馈，我们会及时处理，谢谢

本文最后更新于2023年12月16日，已超过 180天没有更新



首先我们来帝国CMS调用[专题](https://www.xarjtc.com/tag/%e4%b8%93%e9%a2%98 "查看专题此标签更多文章")列表，新建一个自定义列表，代码如下

统计记录：

```
select count(*) as total from [!db.pre!]enewszt
```

查询记录：

```
select ztname as title,ztpath as newspath,ztimg as titlepic,intro as smalltext,ztpath as classid,onclick,ztid as id from [!db.pre!]enewszt
```

然后写列表页的模板，勾选“使用程序代码”，代码如下：

```
$tiao=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsztinfo where ztid='$r[id]'"); $tj=$empire->fetch1("select newstime from {$dbtbpre}enewsztinfo where ztid='$r[id]'"); $tian=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsztinfo where ztid='$r[id]' and '$tj[newstime]'>UNIX_TIMESTAMP()-86400*7"); $yue=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsztinfo where ztid='$r[id]' and '$tj[newstime]'>UNIX_TIMESTAMP()-86400*30"); $listtemp='<li>     <a href="/[!--classid--]">         <img src="[!--titlepic--]">     </a>     <div class="txt">         <h4><a href="/[!--classid--]">[!--title--]</a></h4>         <p><i><b>'.$tiao.'</b>个讨论</i> <i><b>[!--onclick--]</b>个关注</i></p>         <span>7天新增<b>'.$tian.'</b>个讨论, 30天新增<b>'.$yue.'</b>个讨论</span>     </div>     <a href="/[!--classid--]" class="add">+关注</a> </li>';
```

附注：

第一段$tiao为统计当前专题的所有信息数量，$tj为查询当前专题的newstime字段，$tian为统计ztid等于当前专题ID并时间等于7天的信息，$yue同理是统计的30天的信息。