0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

wordpress 記事一覧の最大表示数、次のページ・前のページリンクの追加

Last updated at Posted at 2019-11-14

記事一覧の最大表示数を変更(デフォルト10)

<?php query_posts('posts_per_page=5'); ?>

最新記事5つだけ取得

記事一覧の前後ページリンクを追加


<?php the_posts_navigation(); ?>

次のページ・前のページが表示される


<?php if ( have_posts() ) : ?>
  <?php while( have_posts() ) : the_post(); ?>
    <section class="post-item">
      <!-- タイトルを出力 -->
      <h2><?php the_title(); ?></h2>
   <!-- 記事コンテンツを出力 -->
      <?php the_content(); ?>
    </section>
  <?php endwhile;?>

 <!--前後リンクの追加-->
  <?php the_posts_navigation(); ?>

参考

前後ページ番号付きリンクの追加


<?php the_posts_pagination(); ?>

使用方法は前後ページリンクと同じ

参考

シングルページでの前後ページリンク

<?php the_post_navigation(); ?>

参考

※注意※
query_posts を指定しているページでpost_navigation等を使用するとバグる。。。。
対処法がないか模索中。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?