获取父栏目名称
{dede:field name='id' runphp='yes'}$tsql = new DedeSql(false);$typelink2 = '';$tsql->SetQuery("Select i.typedir,i.typename From #@__arctype t left join #@__arctype i on i.id=t.reid where t.id='@me'");$tsql->Execute('t');while($row = $tsql->GetArray('t',MYSQL_ASSOC)){$typelink2 .= $row['typename'];}@me=$typelink2;{/dede:field}
如果你觉得在模板中嵌入这么长的php代码很不美观的话,也可以将其写成一个函数放入include/extend.func.php文件中,例如:
function GetParentCategoryNameByID($CurrentID){
$tsql = new DedeSql(false);
$typelink2 = '';
$tsql->SetQuery("Select i.typedir,i.typename From #@__arctype t left join #@__arctype i on i.id=t.reid where t.id='$CurrentID'");
$tsql->Execute('t');
while($row = $tsql->GetArray('t',MYSQL_ASSOC))
{
$typelink2 .= $row['typename'];
}
return $typelink2;
}
调用方法:{dede:field name='id' function='GetParentCategoryNameByID(@me)' /}