织梦网站栏目统计标签及文章数量统计标签的使用。在做博客站时,经常需要显示栏目的文章数量,如下图:
第一种:根据所在栏目ID自动判断显示所在栏目的文章数
(<span>[field:ID runphp='yes'] @me = GetTotalArc(@me);[/field:ID]</span>)
第二种:指定栏目ID
{dede:sql sql="SELECT count( ID ) AS c FROM dede_archives where typeid = 栏目id "}
本月更新:[field:c /]篇 {/dede:sql}
第三种:DedeCMS栏目文章数量统计调用,栏目名称按照文章数量排列
{dede:sql sql='SELECT d.typename,d.id,count(da.id) as heji FROM dede_arctype d left join dede_archives da on da.typeid=d.id where d.reid=0 group by d.typename order by heji desc limit 0,8;'}
<span class="text_1"><span class="count">[[field:heji/]篇]</span><a href="http://www.
dedecmsmuban.com/plus/list.php?tid=[field:id/]">[field:typename/]共投递稿件</a></span><br />
{/dede:sql}
第四种:修改include/common.func.php
在最后加入代码:
//*****统计栏目文章数
function GetTotalArc($tid)
{
global $dsql;
$sql = GetSonIds($tid);
$row = $dsql->GetOne("Select count(id) as dd From dede_archives where typeid in({$sql})");
return $row['dd']; }
在htm 最下方添加:
{dede:channel type='top' row='8'}<LI>[field:typename/](<span>[field:ID runphp='yes'] @me = GetTotalArc(@me);[/field:ID]</span>)</LI>{/dede:channel}
如果想调用副栏目的数量 就是
//*****统计栏目文章数
function GetTotalArc($tid2){
global $dsql;
$sql = GetSonIds($tid2);
$row = $dsql->GetOne("Select count(id) as dd From dede_archives where typeid2 in({$sql})");
return $row['dd']; }
HTM页面不变
现在我们来说说动态调用栏目文章数:
动态调用主要针对当前列表页的栏目,而当前的栏目是动态的,因此可以利用type标签调用一个函数就行了。
要调用函数就得增加函数,打开include/common.func.php,在其中任一行(<?与?>的中间任一行)中加上如下函数。
function dynamic_num($current_id){
global $dsql;
$t_num = $dsql->GetOne("select count(*) as num from `dede_archives` where typeid='$current_id'");
if(is_array($t_num)){
return "本栏目共有".$t_num[num]."篇文章";
}else{
return "本栏目共有0篇文章" ;
}
}
在列表页中这样调用:
{dede:type}[field:id function="dynamic_num(@me)" /]{/dede:type}
{dede:sql sql="SELECT count( * ) AS c FROM cmsxx_archives WHERE pubdate > UNIX_TIMESTAMP( CURDATE( ) ) "}
<li class="count">今日更新:<span>[field:c/]</span> 篇</li>
{/dede:sql}
{dede:sql sql="Select count(ID) as c From cmsxx_archives WHERE FROM_UNIXTIME(pubdate,'%m')=month(curdate())"}
<li class="count">当月更新:<span>[field:c/]</span> 篇</li>
{/dede:sql}
{dede:sql sql="select count(*) as c from cmsxx_archives}
<li class="count">共有文章:<span>[field:c/]</span> 篇</li>
{/dede:sql}
{dede:sql sql="select sum(click) as c from cmsxx_archives"}
<li class="count">总共阅读:<span>[field:c/]</span> 人次</li>
{/dede:sql}
{dede:sql sql="select count(mid) as c from cmsxx_member "}
<li class="count">共有会员:<span>[field:c/]</span> 名</li>
{/dede:sql}
还可以指定栏目ID,例如:
{dede:sql sql="select count(*) as c from cmsxx_archives where channel in(1,2,3,5,6,9)"}
<li class="count">共有文章:<span>[field:c/]</span> 篇</li>
{/dede:sql}