2016-11-05 143 views
1

我有一個搜索結果頁面的問題,我在我的搜索頁面上看到的分頁是數字分頁,我想只有一個像這樣的網址是前一個和下一個分頁:WWW。 mywebsite.com/page/{pagenumber}/?s=word下面是我的代碼,我有麻煩修復它:WordPress的主題自定義分頁

在function.php我對這個

rendering the pagination links 
------------------------------------- 
function thrive_pagination() { 
    global $wp_query; 

    $total_pages = $wp_query->max_num_pages; 

    if ($total_pages > 1) { 

     $current_page = max(1, get_query_var('paged')); 

     if (! is_search()) { 
      echo paginate_links(array(
       'base' => trim(get_pagenum_link(1), "/") . '/%_%', 
       'current' => $current_page, 
       'total' => $total_pages, 
      )); 
     } else { 
      echo paginate_links(array(
       'base' => get_pagenum_link(1) . '%_%', 
       'format' => ((get_option('permalink_structure') && ! $wp_query->is_search) || (is_home() && get_option('show_on_front') !== 'page' && ! get_option('page_on_front'))) ? '?paged=%#%' : '&paged=%#%', 
       // %#% will be replaced with page number 
       'current' => $current_page, 
       'total' => $total_pages, 
      )); 
     } 
    } 
} 

雖然我搜索頁面的分頁代碼是:

<?php $next_page_link = get_next_posts_link(); 
$prev_page_link = get_previous_posts_link(); ?> 

       <ul class="entry-nav"> 
       <?php if ($next_page_link || $prev_page_link && ($next_page_link != "" || $prev_page_link != "")): ?> 
        <?php if (strpos($options['blog_layout'], 'masonry') === false): ?> 
         <li class="button next"><?php thrive_pagination(); ?></li> 
         </ul> 
        <?php endif; ?> 
       <?php endif; ?> 

回答

2

你可以傳遞參數在paginate_links

$args = array(
    'base'    => '%_%', 
    'format'    => '?paged=%#%', 
    'total'    => 1, 
    'current'   => 0, 
    'show_all'   => false, 
    'end_size'   => 1, 
    'mid_size'   => 2, 
    'prev_next'   => true, 
    'prev_text'   => __('« Previous'), 
    'next_text'   => __('Next »'), 
    'type'    => 'plain', 
    'add_args'   => false, 
    'add_fragment'  => '', 
    'before_page_number' => '', 
    'after_page_number' => '' 
); 

這是所有的參數信息請閱讀每個參數的使用,您只需要通過「prev_next」爲真,添加prev_text和prev_next參數根據對其格式化您的需要。

echo paginate_links(array(
       'base' => get_pagenum_link(1) . '%_%', 
       'format' => ((get_option('permalink_structure') && ! $wp_query->is_search) || (is_home() && get_option('show_on_front') !== 'page' && ! get_option('page_on_front'))) ? '?paged=%#%' : '&paged=%#%', 
       // %#% will be replaced with page number 
       'current' => $current_page, 
       'total' => $total_pages, 
       'prev_next'=>true, 
       'prev_text'=> __('« Previous'), 
       'next_text'=> __('Next »'), 
      ));