写一个Drupal7有关SEO的小模块
网上有很多Drupal SEO的模块,但是我还都没用过,因为我也觉得这样的代码很简单,所以懒得安装了。
在“似水流云”的博客里,看到了一段代码,所以修改了下就拿来用了。
另外,因为我的文章有两个字段,一个是文章分类,一个是文章标签,而keywords只是文章标签,所以我在 auto_meta_preprocess_page函数做了许多改动,比如我的keywords标签是field_story_keywords,如果 你的关键词字段名跟我的不一样,你必须换成你自己定义的字段名。修改后的这个代码只适合Drupal7,而似水流云的只适合Drupal6。
因为有些分类页面也要修改下title什么的,所以我又在template.php里写了个seo_page函数,然后在mytheme_preprocess_html里调用就行了。
<?php
}
function
} function
}
?>
<?php
//template.php
function seo_page($link, & $variables){
$seo_data = array();
$seo_data [0] = array( 'title' => 'Drupal安装指南,Drupal7专业开发教程-溯游','keywords' => 'Drupal安装指南,Drupal7专业开发教程','description' => '');
$seo_data [1] = array( 'title' => 'Drupal常用模块,Drupal7模块介绍开发-溯游','keywords' => 'Drupal常用模块,Drupal7模块介绍,Drupal模块开发','description' => '');
$seo_data [2] = array( 'title' => 'Drupal主题下载,Drupal7主题制作指南-溯游','keywords' => 'Drupal主题下载,Drupal7主题制作指南','description' => '');
$seo_data [3] = array( 'title' => 'Drupal中文资讯,Drupal7汉化及互联网那些事儿-溯游','keywords' => 'Drupal中文,Drupal7汉化','description' => '');
$seo_data [4] = array( 'title' => 'Drupal blogs-溯游' ,'keywords' => 'drupal blogs' , 'description' => '');
$data = array();
if( $link == 'taxonomy/term/12'){
$data = $seo_data[1];
}elseif( $link == 'taxonomy/term/10'){
$data = $seo_data[2];
}elseif( $link == 'node/7'){
$data = $seo_data[0];
}elseif( $link == 'node/11'){
$data = $seo_data[3];
}elseif( $link == 'blog'){
$data = $seo_data[4];
}
if(!empty( $data)){
$meta_description = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'name' => 'description',
'content' => $data['description']
)
);
$meta_keywords = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'name' => 'keywords',
'content' => $data['keywords']
)
);
if(isset( $variables['head_title'])){$variables['head_title'] = $data['title'];}
drupal_add_html_head($meta_keywords, 'meta_keywords');
drupal_add_html_head($meta_description, 'meta_description');
}
}
?>
转载自:http://suyou.info/node/30
posted on 2011-03-29 11:57 kingQueenyun 阅读(1350) 评论(0) 收藏 举报
浙公网安备 33010602011771号