1. 程式人生 > >dedecms 自動獲取上級欄目的標題,關鍵字和描述

dedecms 自動獲取上級欄目的標題,關鍵字和描述

ml2 empty 欄目 words ddt 一段 == get from

<title>{dede:field.seotitle/}</title>
<meta name="keywords" content="{dede:field name=‘keywords‘/}" />
<meta name="description" content="{dede:field name=‘description‘ function=‘html2text(@me)‘/}" />

第一步:打開/include/typelink.class.php 找到這一段代碼 $this->TypeInfos = $this->dsql->GetOne($query); 在他下面加上三行代碼加好之後如下

     //載入類目信息 
     $query = "SELECT tp.*,ch.typename as ctypename,ch.addtable,ch.issystem FROM `dede_arctype` tp left join `dede_channeltype` ch 
     on ch.id=tp.channeltype  WHERE tp.id=‘$typeid‘ "; 
     if($typeid > 0) 
     { 
         $this->TypeInfos = $this->dsql->GetOne($query); 
//填空 
$this->TypeInfos[‘keywords‘] = $this->TypeInfos[‘keywords‘] ? $this->TypeInfos[‘keywords‘] : $this->GetTrueInfos(‘keywords‘); 
$this->TypeInfos[‘seotitle‘] = $this->TypeInfos[‘seotitle‘] ? $this->TypeInfos[‘seotitle‘] : $this->GetTrueInfos(‘seotitle‘); 
$this->TypeInfos[‘description‘] = $this->TypeInfos[‘description‘] ? $this->TypeInfos[‘description‘] : $this->GetTrueInfos(‘description‘); 
         if(is_array($this->TypeInfos)) 
         { 
             $this->TypeInfos[‘tempindex‘] = MfTemplet($this->TypeInfos[‘tempindex‘]); 
             $this->TypeInfos[‘templist‘] = MfTemplet($this->TypeInfos[‘templist‘]); 
             $this->TypeInfos[‘temparticle‘] = MfTemplet($this->TypeInfos[‘temparticle‘]); 
         } 
     }

第二步:在TypeLink類中增加一個調用方法GetTrueInfos($info) 代碼如下:

//為了讓某些欄目的關鍵字描述等不能為空 
   function GetTrueInfos($info = ‘seotitle‘) {   
 $infos = array(‘reid‘=>$this->TypeID,$info=>‘‘); 
 while(empty($infos[$info]) && $infos[‘reid‘]!=0) { 
  $this->dsql->SetQuery("SELECT reid,".$info."  FROM dede_arctype WHERE id=‘".$infos[‘reid‘]."‘"); 
     $infos = $this->dsql->GetOne(); 
 } 
 if(empty($infos[$info])) { 
  if($info == "seotitle") return $GLOBALS[‘cfg_webname‘]; 
  if($info == "keywords") return $GLOBALS[‘cfg_keywords‘]; 
  if($info == "description") return $GLOBALS[‘cfg_description‘]; 
 } 
    return $infos[$info]; 
   } 
保存之後,這裏我們去生成一下預覽效果,此方法在DEDECMS 5.7 SP1上測試有效,其它版本未測試。

dedecms 自動獲取上級欄目的標題,關鍵字和描述