SEO之文章自动生成独一无二的描述

虽然在很用心地经营网站,但网站搜索排名并不好,今天彻底改动了一下,每篇文章都会自动生成一个独一无二的描述(description),然后将描述放在<meta name=”description” content=”独一无二的内容”>中。本博客使用了wordpress 插件——wordpress seo by yoast?,发表文章时可以自己设置描述内容及关键字,此插件也可自动生成描述内容。本站首页的描述内容是我自己写的一个函数生成的。
本站首页生成描述内容的函数见下面
// 输出指定位置之前的内容,使用<!–more–>分隔符来分割文摘内容。
function excerpt($post_content, $id){
$theendposition=strrpos($post_content, ‘<!–more–>’);
if($theendposition<>0)
return substr($post_content,0,$theendposition).” <a class=’readmore’ href=’post.php?id=$id’>详细内容</a>”;
else
return $post_content;
}
在文章详细页面增加下面的meta元标签
<meta name=”description” content=”<?=$post_title . ‘ – ‘ . substr(strip_tags(excerpt($post_content, $id)),0,200)?>” />
具体效果可以参考本站首页源代码。
附:substr() 和 ?strip_tags() 是php自带的函数。substr()用来截取字符串中的字符;strip_tags()用来过滤掉字符串中所有的html ?css php等标记。
上一个:网页设计要易于浏览
下一个:网络政治文化的基本内涵
衡阳县网站建设,衡阳县做网站,衡阳县网站设计