blog
copyright ©
creamu Inc. All Rights Reserved.
art direction & design: Kunitaka Kawashimo
code, interaction & photography: creamu Inc.
category: Technology

WordPressのquery_postsの書き方と止める方法

Pocket

WordPressでループに条件を指定する場合、 query_postsを使って以下のように書きます。 この場合は「showposts=5」で記事を5件表示しています。 <?php if (have_posts()) : query_posts(‘showposts=5’); ?> <ul> <?php while (have_posts()) : the_post(); ?> <li><a href=”<?php the_permalink() ?>”> <?php the_title(); ?> </a></li> <?php endwhile; ?> </ul> <?php endif; ?> <?php wp_reset_query(); ?> 「<?php wp_reset_query(); ?>」と書いてquery_postsをリセットしておかないと、 それ以降のループに影響して表示がおかしくなる場合があります。