WordPressカスタム投稿ページネーション

WordPressにおいて、アーカイブページやカスタム投稿などの一覧ページを表示する際、
ページネーションの設定。

シンプルなループを使って一覧を表示する場合

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
// 以下、表示したい内容記述
<?php endwhile; endif; wp_reset_postdata(); ?>
 
// ページネーション
<div class="page">// クラス名は任意
<?php echo paginate_links( array ( 'type' => 'list',
	'prev_text' => '«',
	'next_text' => '»'
)); ?>
</div>

このコードで、ページネーションが表示されます。

特定のカスタム投稿などを絞り込んで一覧表示する場合

<?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
    'post_type' => 'post_type',
    'posts_per_page' => 10,// 記述しなければ、管理画面 > 表示設定で設定した件数が使用されます。
    'paged' => $paged,
);
$the_query = new WP_Query($args);
if($the_query->have_posts()) : 
    while($the_query->have_posts()) : $the_query->the_post();
?>
 
// 以下、表示したい内容の記述
 
// ページネーション
<div class="page">// クラス名は任意
<?php echo paginate_links( array ( 'type' => 'list',
	'prev_text' => '«',
	'next_text' => '»'
)); ?>
</div>