DEDECMS 獲取指定欄目下面的文章數量,可以寫一個自己的小助手,然後再用function去調用 。
第一步:打開/include/helpers/channelunit.helper.php 在裏面增加一個方法getTypeArcLength(addson=true) 代碼如下
/**
* 獲取指定欄目下面的文章數量
*
* @param string $id 欄目id
* @param string $addthis 是否包含子欄目
* @return string
*/
if ( ! function_exists('getTypeArcLength')) {
function getTypeArcLength($id,$addson=true) {
global $dsql;
if($addson) {
$types = GetSonIds($id);
$sql = "SELECT count(id) as len FROM idea_arctiny where typeid IN ($types)";
} else {
$sql = "SELECT count(id) as len FROM idea_arctiny where typeid = $id";
}
$arclen = $dsql->GetOne($sql);
return $arclen['len'];
}
}
第二步:在模板用調用,可以在任意位置調用,只要是能調出欄目的地方,比如type標籤等,function方法的使用就不說了,如果有需要的去看我之前寫過的一些文章。
1
{dede:field.id function="getTypeArcLength(@me,false)"/}
2
3
{dede:type typeid='24'}
4
[field:id function="getTypeArcLength(@me,false)"/]
5
{/dede:type}