特定カテゴリーの新着情報のループ
<div id="front_page"> <h2>最新情報</h2> <?php $my_query = new WP_Query('&cat=10'); ?> <?php if ($my_query->have_posts()) : ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> <div class="article_block"> <dl> <dt><?php the_date() ?></dt> <dd><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dd> </dl> </div> <?php endwhile; ?> <?php endif; ?> </div>
Wp_queryの条件文
条件設定サンプル<?php $my_query = new WP_Query(array('orderby'=>'date','order' => 'DESC','cat' =>'6')); ?>
カテゴリースラッグで表示カテゴリーを指定
‘category_name’ => ‘カテゴリーのスラッグ名’カテゴリーIDで表示カテゴリーを指定
‘cat’ => ‘カテゴリーID’固定ページだけ表示
‘pagename’ => ‘固定ページのスラッグ’表示数指定
‘posts_per_page’ => ‘件数’並び順を指定
‘orderby’ => ‘キー’,’order’ => ‘並び順’・キー
date→日付順
modified→最終更新日時順
ID→ページのID順
rand→ランダム
comment_count→コメント数順
meta_value→カスタムフィールドの値順
・並び順
昇順:ASC
降順:DESC
スポンサーリンク