织梦Dedecms 调取栏目总记录数

2017-04-13 21:02:31 dedecms

  将以下函数放入include/extend.func.php

//统计栏目文章数 function GetTotalArc($tid){ global $dsql; $sql = GetSonIds($tid); $row = $dsql->GetOne("Select count(id) as dd From `dede_archives` where typeid in({$sql})"); return $row['dd']; } //统计当前栏目信息数 function dynamic_num($current_id){ global $dsql; //读取当前栏目的子ID $sql = "SELECT id FROM `dede_arctype` WHERE id='$current_id' || topid='$current_id'"; $dsql->SetQuery($sql); $dsql->Execute(); while($row = $dsql->GetArray()){ $arr[]=$row[id]; } foreach($arr as $key=>$value){ $type .= $value . ','; } $ty= "".$type."0"; //echo $ty; $t_num = $dsql->GetOne("select count(*) as num from `dede_archives` where typeid in($ty)"); //echo $t_num[num]; if(is_array($t_num)){ return " ".$t_num[num]." "; }else{ return "0" ; } }

  模板中使用以下标签调用:

{dede:field name=’typename’/}</b>(此栏目共{dede:type}[field:id function="dynamic_num(@me)" /]{/dede:type}条记录) {dede:channel type=’son’ } <li><a href=’[field:typelink/]‘>[field:typename/]</a>(<span>[field:ID runphp='yes'] @me = GetTotalArc(@me);[/field:ID]</span>)</li> {/dede:channel}

  以上代码是两个函数,一个统计栏目文章数,另一个统计当前栏目信息数。