Home > Article > CMS Tutorial > How does DEDECMS get the number of articles in the current column and all sub-columns?
DEDECMS How to get the number of articles in the current column and all sub-columns?
The following code is used to query the total number of articles in the current column and all sub-columns under the current column, and is added to /include/common.func.php
or /include/extend. func.php, and then call getTotalArcByTid(1) in the template.
Recommended learning: Dream Weaver cms
The code is as follows:
/* * 返回符合记录的文章数量 * @description DEDE不允许执行子查询,解决栏目下文章统计的问题 * @param $level 为真时查询所有子类目 * */ 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']; } /* * 递归获取符合条件的子栏目 * @param $tid 栏目ID * @return string * */ 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,','); }
Calling method:
The method called in the template is generally :
{dede:field.typeid function="getTotalArcByTid(@me)"/}
or
[field:typeid function="getTotalArcByTid(@me)"/]
The above is the detailed content of How does DEDECMS get the number of articles in the current column and all sub-columns?. For more information, please follow other related articles on the PHP Chinese website!