【WPの基本】すべての投稿の一覧を表示する方法

2021/2/13

2021/10/5

1784 views

投稿一覧表示

WordPressですべての投稿記事の一覧を表示する方法です。
トップページなどで使えると思います。
下記のコードを表示したいテンプレートファイルに記述ください。

<?php
$paged = (int) get_query_var('paged');
$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',//公開記事のみ
    'orderby' => 'date',//日付順
    'order' => 'DESC',//昇順
    'posts_per_page' => 20,//最大表示数
    'paged' => $paged
);
$the_query = new WP_Query($args);
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<article>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="indexpostloopimg scale">
<?php $post_title = get_the_title();
  the_post_thumbnail('thumbnail',
    array(
      'alt' => $post_title,
      'title' => $post_title
    )
  );
?>
</div>
<p><?php the_time('Y.n.j'); ?></p>
</article>
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>

以上です。
ご質問などありましたらお気軽にコメントください。

この記事へのコメント

  • まだ書き込みはありません

コメントを残す



このサイトの表示速度はどうですか?

当サイトはレンタルサーバーにConoHa WING(コノハウイング)を使っていますよ。

ページの先頭に戻る