2016-11-05 113 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 »'), 
      ));