增加统计栏目文章数的方法
实现方法:
打开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'];
}
//统计栏目文章数结束
调用方法:
[field:ID function='GetTotalArc(@me)'/]//此中调用当栏目下无文章时显示“空”
或
[field:ID runphp='yes'] @me = GetTotalArc(@me);[/field:ID]//此中调用当栏目下无文章时显示“0”
示例:
调用指定栏目ID的栏目文章数:
{dede:type typeid='1'}[field:typename/]([field:ID function='GetTotalArc(@me)'/]){/dede:type}
{dede:type typeid='1'}[field:typename/]([field:ID runphp='yes'] @me = GetTotalArc(@me);[/field:ID]){/dede:type}
调用顶级栏目的栏目文章数:
{dede:channel type='top' row='10' currentstyle="<li class='hover'><a href='~typelink~' ~rel~><span>~typename~</span></a></li>"}
<li><a href='[field:typeurl/]' [field:rel/]><span>[field:typename/]([field:ID function='GetTotalArc(@me)'/])</span></a></li>
{/dede:channel}
{dede:channel type='top' row='10' currentstyle="<li class='hover'><a href='~typelink~' ~rel~><span>~typename~</span></a></li>"}
<li><a href='[field:typeurl/]' [field:rel/]><span>[field:typename/]([field:ID runphp='yes'] @me = GetTotalArc(@me);[/field:ID])</span></a></li>
{/dede:channel}
调用某一栏目下子栏目的文章数:
{dede:channel type ='son' typeid ='1' row='10' currentstyle="<li class='hover'><a href='~typelink~' ~rel~><span>~typename~</span></a></li>"}
<li><a href='[field:typeurl/]' [field:rel/]><span>[field:typename/]([field:ID function='GetTotalArc(@me)'/])</span></a></li>
{/dede:channel}
{dede:channel type ='son' typeid ='1' row='10' currentstyle="<li class='hover'><a href='~typelink~' ~rel~><span>~typename~</span></a></li>"}
<li><a href='[field:typeurl/]' [field:rel/]><span>[field:typename/]([field:ID runphp='yes'] @me = GetTotalArc(@me);[/field:ID])</span></a></li>
{/dede:channel}
文章页/栏目页调用当前栏目的文章数:
{dede:type}[field:typename/]([field:ID function='GetTotalArc(@me)'/]){/dede:type}
{dede:type}[field:typename/]([field:ID runphp='yes'] @me = GetTotalArc(@me);[/field:ID]){/dede:type}