由于功能需要,想在页面中获得当前栏目所属的顶级栏目的权重和二级栏目的权重(用于导航条自动高亮)
在网上搜到了一些朋友提供的方法,但是可能是版本更新的缘故导致不能用了(当时数据库中用topid标注顶级栏目id,用reid标注上级栏目id,但是在5.7版本中经确认两者已合一表示上级栏目id)
根据别人的方法,修改如下,5.7版可用
在include/extend.func.php中添加以下代码:
//获取所属顶级栏目的名字function GetTopTypeName($id){global $dsql;$row = $dsql->GetOne(“SELECT typename,topid FROM dede_arctype WHERE id= $id”);if ($row['topid'] == ’0′){return $row['typename'];}else{return GetTopTypeName($row['topid']);}}//获取所属顶级栏目的sortrankfunction GetTopTypeSortrank($id){global $dsql;$row = $dsql->GetOne(“SELECT sortrank,topid FROM dede_arctype WHERE id= $id”);if ($row['topid'] == ’0′){return $row['sortrank'];}else{return GetTopTypeSortrank($row['topid']);}}//获取二级栏目名function GetSecondTypeName($id){global $dsql;$row = $dsql->GetOne(“SELECT typename,topid FROM dede_arctype WHERE id= $id”);if ($row['topid'] == ’0′) //如果本栏目就是顶级栏目,即不存在二级栏目,则返回本级栏目{return $row['typename'];}else{$row2 = $dsql->GetOne(“SELECT typename,topid FROM dede_arctype WHERE id= $row[topid]“);if ($row2['topid'] == ’0′) //如果上级栏目就是顶级栏目,即本级栏目就是二级栏目,则返回本级栏目{return $row['typename'];}else{return GetSecondTypeName($row['topid']);}}}//获取二级栏目Sortrankfunction GetSecondTypeSortrank($id){global $dsql;$row = $dsql->GetOne(“SELECT sortrank,topid FROM dede_arctype WHERE id= $id”);if ($row['topid'] == ’0′){return $row['sortrank'];}else{$row2 = $dsql->GetOne(“SELECT sortrank,topid FROM dede_arctype WHERE id= $row[topid]“);if ($row2['topid'] == ’0′) //如果上级栏目就是顶级栏目,即本级栏目就是二级栏目,则返回本级栏目{return $row['sortrank'];}else{return GetSecondTypeSortrank($row['topid']);}}}页面调用方法:{dede:field name=’typeid’ runphp=’yes’}@me=GetTopTypeName(@me)-1;
如果本文对你有帮助,欢迎打赏本站