dede自动动获取上级栏目的标题 关键字 描述,DED
导读:DEDE技术DEDE技术当我们做大型网站的时候,上百个栏目,为了SEO,在栏目模板里面,我们一般会像下面这样去调用栏目标题、关键字、描述。 title{dede:field.seotidede网站模板dede5.7模板。
当我们做大型网站的时候,上百个栏目,为了SEO,在栏目模板里面,我们一般会像下面这样去调用栏目标题、关键字、描述。
<ti织梦模板下载tle>{dede:field.seotitle/}</title>
<meta name="keywords" content="{dede:field name='keywords'/}" />
<meta name="description" content="{dede:field name='description' function='html2text(@me)'/}" />
但是这样有一个问题,就是假如个别栏目忘记写标题、关键字、描述就会为空了。这时我们可能就会想,如果能让栏目标题、关键字、描述为空的时候,就调用上级的就好了,当上级没有时候时候,再调用上上级的,如果到顶级栏目都还没有的时候,就调用用网站首页的标题、关键字、描述,想法是可以,但是实现起来可能不容易。今天我就来分享一下我的方法吧。
DEDECMS 自动获取上级栏目的标题,关键字 描述
第dede会员中心模板一步:打开/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'] ? $thidede免费校板下战s->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上测试有效,其它版本未测试。 在此献丑了相关dede网站模板dede5.7模板。
声明: 本文由我的SEOUC技术文章主页发布于:2023-07-20 ,文章dede自动动获取上级栏目的标题 关键字 描述,DED主要讲述标题,上级,DEDE技术网站建设源码以及服务器配置搭建相关技术文章。转载请保留链接: https://www.seouc.com/article/web_31237.html