2015-04-06 114 views
2

在類別.php頁面中,默認的帖子是通過分頁顯示的,而'category'是從永久鏈接設置中的url中刪除的。Wordpress category.php頁面分頁顯示404頁面

不幸的是,它重定向到404頁面,而分頁到第二頁。

我甚至試圖檢查在wordpress默認2015年主題它不會在那裏工作的類別分頁。

這裏是我的category.php只是用於測試的wordpress循環。

if (have_posts()) : 
    while (have_posts()) : the_post(); 
     the_title(); 
    endwhile; 
endif; 

next_posts_link('Older posts'); 
previous_posts_link('Newer posts'); 

注意:如果類別沒有從網址中刪除,一切正常。

http://www.domain.com/category/my_category/page/2 (works) 
http://www.domain.com/my_category/page/2 (doesnt work) 

我需要添加/修改任何東西才能使其工作嗎?

+0

以下插件將幫助:https://wordpress.org/plugins/remove-category-url/ – 2015-04-06 10:56:39

+0

http://stackoverflow.com/questions/17798815/remove -category標籤的鹼基從-WordPress的-URL,而無需-A-插件 – atinder 2015-07-14 05:15:48

回答

2

這是正常現象,請嘗試使用下面的代碼:

add_filter('category_rewrite_rules', 'vipx_filter_category_rewrite_rules'); 
function vipx_filter_category_rewrite_rules($rules) { 
    $categories = get_categories(array('hide_empty' => false)); 

    if (is_array($categories) && ! empty($categories)) { 
     $slugs = array(); 
     foreach ($categories as $category) { 
      if (is_object($category) && ! is_wp_error($category)) { 
       if (0 == $category->category_parent) { 
        $slugs[] = $category->slug; 
       } else { 
        $slugs[] = trim(get_category_parents($category->term_id, false, '/', true), '/'); 
       } 
      } 
     } 

     if (! empty($slugs)) { 
      $rules = array(); 

      foreach ($slugs as $slug) { 
       $rules[ '(' . $slug . ')/feed/(feed|rdf|rss|rss2|atom)?/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]'; 
       $rules[ '(' . $slug . ')/(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]'; 
       $rules[ '(' . $slug . ')(/page/(\d+)/?)?$' ] = 'index.php?category_name=$matches[1]&paged=$matches[3]'; 
      } 
     } 
    } 
    return $rules; 
} 

重要編輯:有分頁中的一個bug,10+沒有正常工作的網頁。
現在修正:(\d)+更改爲(\d+)

希望這會有所幫助:)