件数を指定して新着情報を表示

wordpressのテーマを編集する際の個人的な覚書です。

<?php
$information= get_posts( array(
'posts_per_page' => 取得する件数
));
if( $information):
?>
<ul>
<?php
foreach( $information as $post ):
setup_postdata( $post );
?>
<li>
<?php the_time('Y年n月j日'); ?> - <a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a>
</li>
<?php
endforeach;
wp_reset_postdata();
?>
</ul>
<?php else: ?>
<p>表示できる情報はありません。</p>
<?php endif; ?>

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です