織夢Dedecms 調取欄目總記錄數
阿新 • • 發佈:2019-01-02
這裡是引用
將以下函式放入include/extend.func.php
//統計欄目文章數 function GetTotalArc($tid){ global $dsql; $sql = GetSonIds($tid); $row = $dsql->GetOne("Select count(id) as dd From `#@__archives` where typeid in({$sql})"); return $row['dd']; } //統計當前欄目資訊數 function dynamic_num($current_id){ global $dsql; //讀取當前欄目的子ID $sql = "SELECT id FROM `#@__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 `#@__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}
以上程式碼是兩個函式,一個統計欄目文章數,另一個統計當前欄目資訊數。