2013-01-01 41 views
0

我已經使用wordpress下面的代碼在本地主機模板分頁,但不知道爲什麼它不工作。它顯示所有頁面很好,但任何頁碼我點擊其唯一顯示第一頁。wordpress分頁不能在localhost服務器工作

global $wp_query; 
$total_pages = $wp_query->max_num_pages; 
if ($total_pages > 1){ 
$current_page = max(1, get_query_var('paged')); 
echo paginate_links(array( 
    'base' => get_pagenum_link(1) . '%_%', 
    'format' => '/page/%#%', 
    'current' => $current_page, 
    'total' => $total_pages, 
)); 
} 

我的永久鏈接設置爲:

本地主機/我 - 博客/樣品後/

和查詢後:

的$ args =陣列(' post_type'=>'post','posts_per_page'=> 2);

有人請給我想法接下來要做什麼這個分頁。

回答

1

這適用於WP_Query。你可以試試它:

global $wp_query; 
$big = 999999999; // Need an unlikely integer 
echo paginate_links(array('base' => str_replace($big, '%#%', get_pagenum_link($big)), 
          'format' => '?paged=%#%', 
          'current' => max(1, get_query_var('paged')), 
          'total' => $wp_query->max_num_pages, 
          'end_size'=> 1, 
          'mid_size'=> 10)); 

Settings -> Readings設置Blog pages show at most您要在每個頁面中顯示的帖子數量和Settings -> Discussion設置分頁行爲烏爾答覆

+0

謝謝@Felipe Alameda A ..它的工作 –

+0

不客氣 –

1
<global $wp_query; 
$total = $wp_query->max_num_pages; 
// only bother with the rest if we have more than 1 page! 
if ($total > 1) { 
    // get the current page 
    if (!$current_page = get_query_var('paged')) 
      $current_page = 1; 
    // structure of "format" depends on whether we're using pretty permalinks 
    $format = empty(get_option('permalink_structure')) ? '&page=%#%' : 'page/%#%/'; 
    echo paginate_links(array(
      'base' => get_pagenum_link(1) . '%_%', 
      'format' => $format, 
      'current' => $current_page, 
      'total' => $total, 
      'mid_size' => 4, 
      'type' => 'list' 
    )); 
} 

請設置一個參數按要求,同時參考這個鏈接My helps you

讓我知道,如果你面對的問題

感謝和問候

+0

感謝..有同樣的問題。顯示第一頁,但我的網址顯示> // localhost/my-blog/page/2 –

+0

檢查這個和它的工作對我來說@mehedidoha – Jalpesh

相關問題