これはホントに保存版。
固定ページに投稿一覧を出力してページャー作成したいときって、なんでいつもこんなに時間がかかるんだろう・・
ってくらいうまく行かない!!!ということで我ながらカスタマイズして動いたものをどうぞ。
これを固定ページにインクルードして読み込む。
備忘録なので、「posts_per_page」とか「cat」とか、出力されるループ処理とかは適宜変えるとよろしい。
<?php
$paged = (int) get_query_var('paged');
$args = array(
'posts_per_page' => 10,
'cat' => 3,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish'
);
$the_query = new WP_Query($args);
if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post();
?>
<dl>
<dt><i class="far fa-calendar-alt"></i><?php echo get_the_date('Y年m月d日'); ?></dt>
<dd>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
</dd>
</dl>
<?php endwhile; else: ?>
<p><?php echo "お探しの記事、ページは見つかりませんでした。"; ?></p>
<?php endif; ?>
<?php
if ($the_query->max_num_pages > 1) {
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%/',
'current' => max(1, $paged),
'total' => $the_query->max_num_pages
));
}
wp_reset_postdata();
?>