用wordpress建立网站的强大和方便成为很多站长们第一首选,所以建站中遇到了许多问题,其中遇到了wordpress的URL中显示有category基于wordpress优化在URL有多余的关键字也许对搜索引擎优化不友好或者是感觉多余,但是我们的一个目的就是移除URL中的category。
(1)推荐大家使用这样形式的固定链接:
[code]/%category%/%postname%/[/code]
目的不仅可以实现我们要的URL结构也对wordpress优化起作用。
使用这样的固定链接之后我们的导航URL就是这样显示:
http://www.xxx.com/xiangmu/
如果你所发的文章归类在xiangmu中,文章的URL地址就是这样显示:
http://www.xxx.com/xiangmu/wenzhang/
(2)在 functions.php添加以下代码:
[code]add_filter(‘user_trailingslashit’, ‘remcat_function’);
function remcat_function($link) {
return str_replace(“/category/”, “/”, $link);
}
add_action(‘init’, ‘remcat_flush_rules’);
function remcat_flush_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_filter(‘generate_rewrite_rules’, ‘remcat_rewrite’);
function remcat_rewrite($wp_rewrite) {
$new_rules = array(‘(.+)/page/(.+)/?’ => ‘index.php?category_name=’.$wp_rewrite->preg_index(1).’&paged=’.$wp_rewrite->preg_index(2));
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}[/code]
这样就可以删除在URL中的category。