Created
July 25, 2012 08:13
-
-
Save ShenXuGongZi/3175024 to your computer and use it in GitHub Desktop.
SEO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (is_home())//首页关键字和描述,可以换成你网站的 | |
{ | |
$description = "小拼:致力于搜索引擎营销(SEM)研究,关注搜索引擎优化(SEO),医院网络营销,SEO技术和电子商务."; | |
$keywords = "SEM,搜索引擎营销,SEO,搜索引擎优化,医院网络营销"; | |
} | |
elseif (is_page())//单独页面关键字和描述,WordPress默认是不显示的,考虑到单独页面也不多,这种判断形式还算快速,只要取得页面对应ID即可 | |
{ | |
if ($post->ID == 1)//数字1是页面的ID,查看方法:鼠标移至对应页面的“编辑”字样上,状态栏出现的链接,形如post.php?post=1&action=edit,其中post=后面的数字1就是对应页面ID | |
{ | |
$description = "小拼,80后草根站长,兴趣颇丰,喜欢写作,关注SEM和医院网络营销,擅长SEO,注重SEO策略和方法,实战经验丰富;此外,小拼对网站设计,DIV+CSS,PHP+MYSQL等也有涉猎."; | |
$keywords = "小拼是谁?,联系小拼"; | |
} | |
elseif ($post->ID == 46) | |
{ | |
$description = "..."; | |
$keywords = "..."; | |
} | |
//可以是多个判断条件下来,按这个逻辑写就行 | |
} | |
elseif (is_single())//文章页关键字和描述 | |
{ | |
$description = $post->post_excerpt ; //这里调用文章的摘要作为描述(description) | |
$keywords = get_post_meta($post->ID, "keywords", true);//注意,这里调用的是文章的“自定义栏目”,不是文章TAG标签。你可以添加一个名称为“keywords”的自定义栏目作为每篇文章的关键字(keywords) | |
} | |
elseif (is_category())//分类目录关键字和描述 | |
{ | |
$description = category_description(); | |
//5.29更新,防止描述为空时导致多个分类目录元描述重复,不利于SEO | |
if (!empty($description) && get_query_var('paged')) {//针对分类描述存在分页时的描述优化,避免“重复的元说明”情况,这是谷歌网站管理员的HTML建议中很重要的概念 | |
$description .= '(第'.get_query_var('paged').'页)'; | |
} | |
$keywords = single_cat_title('', false); | |
} | |
elseif (is_tag())//TAG标签关键字和描述 | |
{ | |
$description = tag_description(); | |
//5.29更新,防止描述为空时导致多个分类目录元描述重复,不利于SEO | |
if (!empty($description) && get_query_var('paged')) { | |
$description .= '(第'.get_query_var('paged').'页)'; | |
} | |
$keywords = single_tag_title('', false);//这里调用TAG标签名称作为关键字(keywords) | |
} | |
$description = trim(strip_tags($description)); | |
$keywords = trim(strip_tags($keywords)); | |
?> | |
<meta name="description" content="<?php echo $description; ?>" /> | |
<meta name="keywords" content="<?php echo $keywords; ?>" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment