9 月 3

ページなどに新着の見出しのみを例えば10件を表示したいときがある。

そんなときは、例えばpage.phpに以下のソースを追加する。

※以下は特定条件ifでくくった場合

<?php if(条件){ ?>

<ul>
<?php
$posts = get_posts(’numberposts=10&offset=0&orderby=post_date’);
 foreach ($posts as $post) :
?>
   <li><a href=”<?php the_permalink(); ?>”><?php the_title() ?></a></li>
<?php
endforeach;
?>
</ul>
<?php } ?>

 

あとはul,liにクラスを追加しCSSで好みのスタイルに整えてください。

get_posts()を勉強しておくといいです。

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

© PHPress since 2008