ワードプレスで、投稿一覧を条件付きで表示させたいという時があると思います。
例えば、投稿日時の新しい順に12件取得するといった場合です。
上記条件の場合のコードは以下になります。
<?php $args = array( 'posts_per_page' => 12, 'orderby' => 'post_date', 'order' => 'ASC', 'post_type' => 'post', 'post_status' => 'publish' ); $the_query = new WP_Query($args); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <li> <?php the_post_thumbnail(); ?> 投稿日時 : <?php the_time('Y/n/j'); ?> <h3><?php the_title(); ?></h3> 値段 : <?= get_post_meta(get_the_ID(), '_price', true); ?> <a href="<?php the_permalink(); ?>">詳細を見る</a> </li> <?php endwhile; endif; ?>画面表示は以下のようになります。
その他、ワードプレスやホームページ制作を格安でご検討であれば弊社までご相談ください。