織夢前端很多時候需要直接獲取一個欄目的相關(guān)信息,獲取在某個頁面上獲取頂級或者上一級欄目的相關(guān)信息,這樣我們可以自己寫個自定義方法來實(shí)現(xiàn)。
打開 \include\extend.func.php 在最下面添加
/** * 獲取頂級欄目相關(guān)信息 * * @access public * @param string $tid 欄目id * @param string $field 欄目字段 * @return string */ if ( ! function_exists('getToptype')) { function getToptype($tid,$field) { global $dsql,$cfg_Cs; if(!is_array($cfg_Cs)) { require_once(DEDEDATA."/cache/inc_catalog_base.inc"); } if(!isset($cfg_Cs[$tid][0]) || $cfg_Cs[$tid][0]==0) { $topid = $tid; } else { $topid = GetTopid($cfg_Cs[$tid][0]); } $row = $dsql->GetOne("SELECT * FROM `dede_arctype` WHERE id=$topid"); if($field=='id') return $topid; if($field=='typename') return $row['typename'];//欄目名稱 if($field=='typeurl') return GetOneTypeUrlA($row);//欄目鏈接 if($field=='typenamedir') return $row['typenamedir'];//欄目英文名稱 if($field=='seotitle') return $row['seotitle'];//欄目SEO標(biāo)題 if($field=='description') return $row['description'];//欄目描述 if($field=='content') return $row['content'];//欄目內(nèi)容 } } /** * 獲取當(dāng)前欄目相關(guān)信息 * * @access public * @param string $tid 欄目id * @param string $field 欄目字段 * @return string */ if ( ! function_exists('getCurtype')) { function getCurtype($tid,$field) { global $dsql; $row = $dsql->GetOne("SELECT * FROM `dede_arctype` WHERE id=$tid"); if($field=='id') return $tid; if($field=='typename') return $row['typename'];//欄目名稱 if($field=='typeurl') return GetOneTypeUrlA($row);//欄目鏈接 if($field=='typenamedir') return $row['typenamedir'];//欄目英文名稱 if($field=='seotitle') return $row['seotitle'];//欄目SEO標(biāo)題 if($field=='description') return $row['description'];//欄目描述 if($field=='content') return $row['content'];//欄目內(nèi)容 } } /** * 獲取上級欄目相關(guān)信息 * * @access public * @param string $tid 欄目id * @param string $field 欄目字段 * @return string */ if ( ! function_exists('getRetype')) { function getRetype($tid,$field) { global $dsql; $typeid = $tid; $query = "SELECT reid FROM `dede_arctype` where id = $typeid"; $rs = $dsql->GetOne($query); $reid = $rs['reid']; $query2 = "SELECT * FROM `dede_arctype` where id = $reid"; $row = $dsql->GetOne($query2); if($field=='id') return $tid; if($field=='typename') return $row['typename'];//欄目名稱 if($field=='typeurl') return GetOneTypeUrlA($row);//欄目鏈接 if($field=='typenamedir') return $row['typenamedir'];//欄目英文名稱 if($field=='seotitle') return $row['seotitle'];//欄目SEO標(biāo)題 if($field=='description') return $row['description'];//欄目描述 if($field=='content') return $row['content'];//欄目內(nèi)容 } } |
模板里調(diào)用方法
需要哪個字段,就對應(yīng)的填上字段名即可
獲取頂級欄目相關(guān)信息
{dede:field.typeid function=getToptype(@me,typename)/}
獲取當(dāng)前欄目相關(guān)信息
{dede:field.typeid function=getCurtype(@me,typename)/}
獲取上級欄目相關(guān)信息
{dede:field.typeid function=getRetype(@me,typename)/}
不喜歡添加自定義方法的同學(xué)可以試試這樣
{dede:field.typeid runphp=yes}global $dsql;$row = $dsql->GetOne("SELECT * FROM dede_arctype WHERE id=@me");$reid = "$row[reid]"; $topid = "$row[topid]";if($reid == 0) @me = $row[content];else $row = $dsql->GetOne("SELECT * FROM dede_arctype WHERE id=$topid");@me = $row[content];{/dede:field.typeid} |
獲取頂級的topid
獲取上級的reid