2013-07-06 140 views
1

在我的wordpress博客中,我使用wp paginate(默認插件)進行分頁。我使用自定義查詢來列出帖子。請參閱this linkWP paginate顯示所有頁面,不受限制,爲什麼?

一切工作正常。我每頁顯示六篇文章(管理員設置),頁面數量正確。但我的問題是所有的頁面都顯示在分頁中。

即1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |>,但我想像這樣| 1 | 2 | 3 | 4 | ... | 10 |>。

我應該怎麼做,我是新來的wordpress。任何人都可以幫忙嗎?

注:

  1. 沒有修改做WP PAGINATE插件。

  2. 在後臺也改變了分頁設置(WP管理員),顯示3頁正面和當前頁面的回來了,它不工作。

我的index.php看起來像這樣:

<?php 
    $paged = get_query_var('paged'); 
    $args = array(
    'post_type' => 'post', 
    'meta_key' => 'wpcf-fn', 
    'orderby' => 'meta_value', 
    'order' => 'ASC', 
    'paged' => $paged 
    ); 
    $cust_query = new WP_Query($args); 
    $temp = $wp_query; 
    $wp_query = $cust_query; 
?> 
<div> *** contents rendered on the page *** </div> 
<div id="navigation" class="clearfix"> 
    <?php if(function_exists('wp_paginate')) : wp_paginate(); ?> 
</div> 
<?php $wp_query = $temp;?> 
+0

對不起,我沒有時間爲一個完整的答案 - 但讀了在[wp_paginate_links](http://codex.wordpress.org/Function_Reference/paginate_links)將爲你做這個 - 也檢查WP_Query中的posts_per_page – Mark

+0

@Eek:This works, [但必須再次處理樣式:(];) – Shathish

回答

3
<?php 
global $wp_query; 

$big = 999999999; // need an unlikely integer 

echo paginate_links(array(
    'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 
    'format' => '?paged=%#%', 
    'current' => max(1, get_query_var('paged')), 
    'total' => $wp_query->max_num_pages, 
    'show_all' => FALSE, //this will make paginate not to show all links. 
    'end_size' => 2, //will show 2 numbers on either the start and the end list edges. 
    'mid_size' => 0 //so that you won't have 1,2...,3,...,7,8 
)); 
?> 

更多細節:http://codex.wordpress.org/Function_Reference/paginate_links