dedecms织梦模板中调用当前栏目文章数量

发布于:2017-06-20   编辑:admin 浏览:

 

此方式合适dedecms5.6及5.7版本
修正织梦程序 include/common.func.php文件,在最后加以下代码:
//统计栏目文章数function GetTotalArc($tid){ global $dsql; $sql = GetSonIds($tid); $row = $dsql->GetOne("Select count(id) as dd From design_archives where typeidin({$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 `design_archives` where typeidin($ty)");//echo $t_num[num];if(is_array($t_num)){ return " ".$t_num[num]." ";}else{ return "0" ;}}织梦模板里的调用代码:

(该类领有{dede:type}[field:id function="dynamic_num(@me)" /]{/dede:type}
个文档)


[field:ID runphp='yes'] @me = GetTotalArc(@me);[/field:ID]

例如模板里增加代码如下:
{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}