/** * 擷取欄目完整URL路徑 by Windchaser QQ:939238564 * @param $typeid 欄目ID|文檔ID * @link http://down.chinaz.com/try/201202/1646_1.htm 從該文章代碼基礎上改編 * @return String */function typeurl_arc($typeid,$type='tid'){ global $dsql,$cfg_basehost; if($type == 'tid'){//擷取欄目完整URL地址 $typeurl = ''; $row = $dsql ->GetOne("SELECT typedir,namerule2,isdefault,typedir,defaultname FROM dede_arctype WHERE id=$typeid"); $row['namerule2'] = str_replace('{typedir}','',$row['namerule2']); $row['namerule2'] = str_replace('{tid}',$typeid,$row['namerule2']); $row['namerule2'] = str_replace('{page}',1,$row['namerule2']); $row['typedir'] = str_replace('{cmspath}','',$row['typedir']); switch ($row['isdefault']) { case 0://連結到列表第一頁 $typeurl = $row['namerule2']; break; case 1://連結到預設頁 $typeurl = $row['typedir'].'/'.$row['defaultname']; break; default://使用動態網頁 $typeurl = '/plug/list.php?tid='.$typeid; break; } }else if($type == 'aid'){//擷取文檔完整URL地址 $row = $dsql ->GetOne("SELECT cnn.namerule,arc.ismake,arc.senddate FROM dede_archives arc JOIN dede_arctype cnn ON arc.typeid=cnn.id WHERE arc.id=$typeid"); if($row['ismake'] == 1){ if(strpos($row['namerule'],'/') == 0){ $row['namerule'] = substr($row['namerule'],1); } $row['namerule'] = str_replace('{aid}',$typeid,$row['namerule']); $row['namerule'] = str_replace('{Y}',date('Y',$row['senddate']),$row['namerule']); $row['namerule'] = str_replace('{M}',date('m',$row['senddate']),$row['namerule']); $row['namerule'] = str_replace('{D}',date('d',$row['senddate']),$row['namerule']); $typeurl = '/'.$row['namerule']; }else{ $typeurl = '/plug/view.php?aid='.$typeid; } } $typeurl = $cfg_basehost.$typeurl; return $typeurl;}
DEDECMS模版標籤的一個擴充方法!
目的是擷取欄目或者文檔的完整URL地址!
文檔和列表的標籤調用小有不同!
列表:
{dede:field.typeid function='typeurl_arc(@me)'/}
文檔:
{dede:field.id function='typeurl_arc(@me,aid)'/}
本文出自 “逆襲逐風” 部落格,請務必保留此出處http://windchaser.blog.51cto.com/5742634/1301449