0

local-host テンプレートのページネーションにコードの下のワードプレスを使用しましたが、なぜ機能しないのかわかりません。すべてのページ番号をうまく表示していますが、どのページ番号をクリックしても最初のページのみが表示されます。

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,  
));  
}

私のパーマリンク設定は次のとおりです。

localhost/my-blog/sample-post/

およびクエリの投稿:

$args = array( 'post_type' => 'post', 'posts_per_page' => 2);

このページネーションを行うために次に何をすべきか、誰か教えてください。

4

3 に答える 3

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 mostSettings -> Discussion

于 2013-01-01T07:29:18.410 に答える
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 Help You

問題が発生した場合はお知らせください

感謝と敬意

于 2013-01-01T06:18:29.767 に答える