Home > CMS Tutorial > DEDECMS > body text

How does DEDECMS get the number of articles in the current column and all sub-columns?

藏色散人
Release: 2019-12-19 09:51:38
Original
2566 people have browsed it

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 = &#39;&#39;; 
while($row=$dsql->GetObject($tid)) 
{ 
$typeid .= "{$row->id},"; 
$typeid .= GetSonTypeID($row->id); 
} 
return trim($typeid,&#39;,&#39;); 
}
Copy after login

Calling method:

The method called in the template is generally :

{dede:field.typeid function="getTotalArcByTid(@me)"/}
Copy after login

or

[field:typeid function="getTotalArcByTid(@me)"/]
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!