dedecms 自动获取上级栏目的标题,关键字和描述

<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上测试有效,其它版本未测试。

 

转载于:https://www.cnblogs.com/hm21/p/10199004.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值