2011-04-13 102 views
4

爲了解決這個問題,我在互聯網上釣魚,嘗試了一兩個插件來從wordpress網址中刪除/ category /。從WordPress類別中刪除類別的網址類別URL

雖然其中一些插件很好,但類別鏈接仍然顯示的/ category /。

此外,我已經嘗試在永久鏈接設置中的類別基礎選項中放入./。

有誰知道我能做些什麼像php搜索和替換或類似的東西?

+0

看起來很有希望 - http://pitumbo.com/remove-category-and-or-tag-url-wordpress-3 – stealthyninja 2011-04-13 22:47:37

+0

不是我在找什麼。我採取了編輯rewrite.php核心文件。問題解決了。 – daryl 2011-04-13 22:50:22

+0

「問題解決了。」事實上,通過改變WP核心,問題變得更加複雜。 – markratledge 2011-04-15 16:44:41

回答

2

http://wordpress.org/extend/plugins/wp-no-category-base/並且它不會更改永久鏈接,因此刪除它可以恢復結構而不會出現問題。而且您不必更改核心文件。

+0

是的,我已經嘗試過這個插件。它沒有做我想做的事情,因爲它仍然在HTML中顯示帶有/ category的HTML鏈接,雖然它重定向到沒有/ category的頁面。 – daryl 2011-04-15 17:39:34

1

一個清潔的解決方案:

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; 
} 
1

使用WordPress 3.9.1(最新版本爲這篇文章的)我只是簡單地添加一行到我的主題的functions.php ...

$wp_rewrite->add_permastruct('category_base', '%category%'); 

然後我打開設置>固定鏈接並點擊保存。這似乎刷新固定鏈接緩存並使其工作。