トップページのみ最新記事5件出したい。
-
トップページのみis_homeで分岐して
loop.phpの投稿の最新記事5件をだしたいのですがなかなかうまくいきません。loop.php抜粋この部分は表示されてました。
<?php if(have_posts()): while(have_posts()): the_post(); ?> <?php $cat = get_the_category(); $cat = $cat[0]; { echo '<li class="' . $cat->category_nicename . '" />'; } ?> <?php the_category(); ?> <time datetime='<?php the_time('Y-m-d'); ?>'> <?php the_time('Y年m月d日'); ?></time> <a href='<?php the_permalink(); ?>'><?php the_excerpt(); ?></a></li> <?php endwhile; endif; ?>分岐の記述をつけたのですが変更後表示されません。
<?php if(is_home()): $args=array( 'post_type' =>'post', 'posts_per_page' =>2, ); $the_query=new WP_Query($args); if($the_query->have_posts()): ?> <?php if(have_posts()): while(have_posts()): the_post(); ?> <?php $cat = get_the_category(); $cat = $cat[0]; { echo '<li class="' . $cat->category_nicename . '" />'; } ?> <?php the_category(); ?> <time datetime='<?php the_time('Y-m-d'); ?>'> <?php the_time('Y年m月d日'); ?></time> <a href='<?php the_permalink(); ?>'><?php the_excerpt(); ?></a></li> <?php endwhile; endif; ?>以上です。どなたかお分かりの方いらっしゃいましたら宜しくお願いいたします。
2件の返信を表示中 - 1 - 2件目 (全2件中)
2件の返信を表示中 - 1 - 2件目 (全2件中)
トピック「トップページのみ最新記事5件出したい。」には新たに返信することはできません。