王尘宇王尘宇

研究百度干SEO做推广变成一个被互联网搞的人

Typecho基本seo优化自定义文章形貌与关键词

SEO就基本的就是TDK了(title description keywords 的缩写,是三个定义标签,中文译为:标题、形貌、关键词),TDK就是用来给搜索引擎看的信息。

Typecho的T就是文章标题,D是截取文章开头的笔墨,K是文章标签,DK的设置显著不是那末太合理,形貌过于枯燥,标签当关键词很不合理。

不过Typecho能够经由过程一些操纵,运用文章自定义字段功用设置形貌与关键词。步骤以下

1,屏障默许输出的关键词与形貌
把模板header.php文件中的<?php $this->header(); ?>改成<?php $this->header('keywords=&description='); ?>

2,为文章强迫设置两个字段
在模板functions.php文件中增加以下代码

function themeFields($layout) {    $description = new Typecho_Widget_Helper_Form_Element_Text('description', NULL, NULL, _t('形貌'), _t('简朴一句话形貌'));$description->input->setAttribute('class', 'text w-100');    $layout->addItem($description);    $keyword = new Typecho_Widget_Helper_Form_Element_Text('keyword', NULL, NULL, _t('产物关键词'), _t('多个关键词用英文下逗号离隔'));$keyword->input->setAttribute('class', 'text w-100');    $layout->addItem($keyword);}

3,让自定义的字段变成文章形貌与关键词
在模板header.php文件中增加以下代码即可

<meta name="description" content="<?php $d=$this->fields->description;if(empty($d) || !$this->is('single')){if($this->getDescription()){echo $this->getDescription();}}else{ echo $d;};?>" /><meta name="keywords" content="<?php $k=$this->fields->keyword;if(empty($k) || !$this->is('single')){echo $this->keywords();}else{ echo $k;};?>" />

如许写好后,在文章页时假如存在自定义字段就会用自定义字段的形貌与关键词,不然就是默许形式。

相关文章

评论列表

发表评论:
验证码

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。