

WordPressで自作のページャーを作成するには、以下のようなコードを使用できます。この例では、paginate_links() 関数を使用して、ページャーを生成します。
<?php
// カスタムクエリを作成
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'post', // ポストタイプ
'posts_per_page' => 5, // 1ページあたりの表示数
'paged' => $paged // 現在のページ番号
);
$custom_query = new WP_Query( $args );
// ページャーの表示
echo '<div class="pagination">';
$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' => $custom_query->max_num_pages,
'prev_text' => '« 前へ',
'next_text' => '次へ »',
) );
echo '</div>';
// カスタムクエリのループ
if ( $custom_query->have_posts() ) :
while ( $custom_query->have_posts() ) : $custom_query->the_post();
// ポストの内容を表示
the_title();
the_content();
endwhile;
wp_reset_postdata();
else :
echo '該当する記事がありません。';
endif;
?>