以下代码用来解决查询当前栏目及当前栏目下所有子栏目的文章总数,添加到/include/common.func.php
或者
/include/extend.func.php中,然后在模板中调用getTotalArcByTid(1)。
复制代码代码如下:
function getTotalArcByTid($tid, $level=TRUE) {
global $dsql;
$level==TRUE && $tid = GetSonTypeID($tid);
$sql = "SELECT count(id) as total from `dede_archives` where typeid in($tid)";
$result = $dsql->GetOne($sql);
return $result['total'];
}
function GetSonTypeID($tid)
{
global $dsql;
$dsql->SetQuery("Select id From `dede_arctype` where reid in($tid) And ishidden<>1 order by sortrank");
$dsql->Execute($tid);
$typeid = '';
while($row=$dsql->GetObject($tid))
{
$typeid .= "{$row->id},";
$typeid .= GetSonTypeID($row->id);
}
return trim($typeid,',');
}
调用方法:
模板中调用的方法一般为:
{dede:field.typeid function="getTotalArcByTid(@me)"/}
或者
[field:typeid function="getTotalArcByTid(@me)"/]