• 全国400电话网上服务平台
    强大号码库资源任选,方便,快捷,快速开通。
    咨询热线:400-1100-266  

    dede自动动获取上级栏目的标题 关键字 描述
    POST TIME:2020-04-10 18:40
    当我们做大型网站的时候,上百个栏目,为了SEO,在栏目模板里面,我们一般会像下面这样去调用栏目标题、关键字、描述。
    <title>{dede:field.seotitle/}</title> <meta name="keywords" content="{dede:field name='keywords'/}" /> <meta name="description" content="{dede:field name='description' function='html2text(@me)'/}" /> 但是这样有一个问题,就是假如个别栏目忘记写标题、关键字、描述就会为空了。这时我们可能就会想,如果能让栏目标题、关键字、描述为空的时候,就调用上级的就好了,当上级没有时候时候,再调用上上级的,如果到顶级栏目都还没有的时候,就调用用网站首页的标题、关键字、描述,想法是可以,但是实现起来可能不容易。今天我就来分享一下我的方法吧。
    DEDECMS 自动获取上级栏目的标题,关键字 描述
    第一步:打开/include/typelink.class.php 找到这一段代码$this->TypeInfos = $this->dsql->GetOne($query); 在他下面加上三行代码加好之后如下
    //载入类目信息 $query = "SELECT tp.*,ch.typename as ctypename,ch.addtable,ch.issystem FROM `idea_arctype` tp left join `idea_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 idea_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上测试有效,其它版本未测试。 在此献丑了
    
    关于我们 | 付款方式 | 建站知识 | 增值服务 | 网站模板
    Copyright © 2003-2016
    时间:9:00-21:00 (节假日不休)
    版权所有:巨人网络(扬州)科技有限公司
    总部地址:江苏省信息产业基地11号楼四层
    《增值电信业务经营许可证》 苏B2-20120278
    X

    截屏,微信识别二维码

    微信号:veteran88

    (点击微信号复制,添加好友)

     打开微信

    微信号已复制,请打开微信添加咨询详情!