Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to get the number of articles in the current column and all sub-columns by DEDECMS

Shulou Source: shulou.com Published: 2022-06-02 03:31:51 09月26日 Update

This article will explain in detail how DEDECMS obtains the number of articles in the current column and all sub-columns. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

How does DEDECMS 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 subcolumns under the current column, adding to / include/common.func.php

Or / include/extend.func.php, and then call getTotalArcByTid (1) in the template.

The code is as follows:

/ * * return the number of articles matching the record * @ description DEDE does not allow subquery to solve the problem of article statistics under the column * @ param $level query all subcategories * * / 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'] } / * * Recursively get eligible subcolumns * @ param $tid column ID * @ return string * * / function GetSonTypeID ($tid) {global $dsql; $dsql- > SetQuery ("Select id From `dede_ arctype` where reid in ($tid) And ishidden1 order by sortrank"); $dsql- > Execute ($tid); $typeid =''; while ($row=$dsql- > GetObject ($tid)) {$typeid. = "{$row- > id},"; $typeid. = GetSonTypeID ($row- > id);} return trim ($typeid,',');}

Call method:

The methods called in the template are generally:

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

Or

[field:typeid function= "getTotalArcByTid (@ me)" /] the number of articles about how DEDECMS gets the current column and all its sub-columns is shared here. I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Column article quantity query code method more template article good practical content subcategory total condition knowledge problem recursion reference help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Information MySQL Xiaomi Shulou Tech Info