• Source
    1. <?php
    2. $args = array(
    3. 'post_type' => 'custom_test', // 投稿タイプのスラッグを指定
    4. 'post_status' => 'publish', // 公開済の投稿を指定
    5. 'order' => 'DESC',
    6. 'posts_per_page' => 5 // 投稿件数の指定
    7. );
    8. $the_query = new WP_Query($args); if($the_query->have_posts()):
    9. ?>
    10. <div id="custom">
    11. <ul class="className">
    12. <?php while ($the_query->have_posts()): $the_query->the_post(); ?>
    13.  
    14.  
    15. <li><a href="<?php the_permalink(); ?>"><span class="day"><?php echo get_the_date( 'Y年n月d日' ); ?></span><span class="label">テスト</span><span class="text">
    16. <?php the_title(); ?></span></a></li>
    17.  
    18.  
    19. <?php endwhile; ?>
    20. <?php wp_reset_postdata(); ?>
    21. </ul>
    22. <div>
    23. <?php else: ?>
    24. <!-- 投稿が無い場合の処理 -->
    25. <div>新着情報はありません。</div>
    26.  
    27. <?php endif; ?>