在做織夢模板時,經(jīng)常需要在每個欄目列表頁加上此欄目的文章數(shù)調(diào)用,下面就教大家具體的實現(xiàn)方法。
首先找到并打開include/common.func.php文件,在最后面加入下面這段代碼:
//統(tǒng)計欄目內(nèi)容條數(shù)
function GetTotalArc($tid){
global $dsql;
$sql = GetSonIds($tid);
$row = $dsql->GetOne("Select count(id) as dd From zmb_archives where typeid
in({$sql})");
return $row['dd'];
}
//統(tǒng)計當前欄目信息數(shù)
function dynamic_num($current_id){
global $dsql;
//讀取當前欄目的子ID
$sql = "SELECT id FROM zmb_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 zmb_archives where typeid
in($ty)");
//echo $t_num[num];
if(is_array($t_num)){
return " ".$t_num[num]." ";
}else{
return "0" ;
}
}
|
然后在列表頁模板里面插入如下調(diào)用代碼:
(該欄目有{dede:type}[field:id function="dynamic_num(@me)" /]{/dede:type}篇文檔)和[field:id runphp='yes'] @me = GetTotalArc(@me);[/field:id]
|
下面是完整的調(diào)用實例:
{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}
|
|