写一个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 & $variables){
   $seo_data array();
    $seo_data = array(  'title' 
   $seo_data = array(  'title' 
   $seo_data = array(  'title' 
   $seo_data = array(  'title' 
   $seo_data = array(  'title' blogs-溯游' ,'keywords' blogs' , 
   $data array();
  if(   $link 
       $data 
  }elseif(  $link 
       $data 
  }elseif(  $link 
       $data 
  }elseif(  $link 
       $data 
  }elseif(  $link 
       $data 
  }
  if(!empty(    $data)){
   $meta_description array(
                        '#type' 
                       '#tag' 
                       '#attributes' array(
                                'name' 
                               'content' 
            )
  );
                 $meta_keywords array(
                        '#type' 
                       '#tag' 
                       '#attributes' array(
                                'name' 
                               'content' 
            )
   );
  if(isset(                 $variables['head_title'])){$variables['head_title'] =  $data['title'];}
   drupal_add_html_head($meta_keywords, 
   drupal_add_html_head($meta_description, 
  }
}
  ?>
转载自:http://suyou.info/node/30
posted on 2011-03-29 11:57 kingQueenyun 阅读(1348) 评论(0) 收藏 举报
 
                    
                     
                    
                 
                    
                 
                
            
         
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号