WordPress 投稿を日付の降順(新しい順)で取得
query_postsを利用する方法ももちろんありますが、ここではquery_postsをもうすでに使用してしまったなどで使えない場合のために、get_posts関数を利用する方法を書いておきます。
たとえば、カテゴリー18の投稿を5件、新しい順に取得して表示するサンプルです。
<div class="new_info"> <?php //query_posts( 'cat=18&orderby=date&posts_per_page=5' ); $args = array('category'=>18, 'numberposts' => 5, 'order'=>'DESC', 'orderby'=>'post_date'); $posts = get_posts( $args ); if ($posts) : ?> <table class="news"> <?php foreach ( $posts as $post ): setup_postdata($post); ?>
<th><?php echo get_post_time('d M Y'); ?></th> <td><div>
get_postsについて
http://wpdocs.sourceforge.jp/%E3%83%86%E3%83%B3%E3%83%97%E3%83%AC%E3%83%BC%E3%83%88%E3%82%BF%E3%82%B0/get_posts
ちなみに、query_postsはループをネストして使えない、というのは下記に書いてあります。
Secondary Loops
To create secondary listings (for example, a list of related posts at the bottom of the page, or a list of links in a sidebar widget), try making a new instance of WP_Query or use get_posts().