taxonomy.php

WordPress

一般的な書き方

<h1><?php echo get_queried_object()->name; ?></h1>
<?php if(have_posts()): while(have_posts()): the_post(); ?>

<?php if(has_post_thumbnail()): ?>
    <a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
<?php endif; ?>
<div>
    <?php the_title(); ?>
    <time datetime="<?php echo get_the_date('Y-m-d'); ?>">
        <?php echo get_the_date('Y/m/d'); ?>
    </time>
</div>


<?php endwhile; endif; ?>

投稿件数を指定する場合

<?php
    $arg = array(
        'post_type' => 'post',
        'taxonomy' => get_queried_object()->taxonomy,
        'term' => get_queried_object()->slug,
        'post_per_page' => 20,
    );
    $posts = new WP_Query($arg);

    if($posts->have_posts()): while($posts->have_posts()): the_post();
?>
--  --
<?php
    endwhile; endif;
?>

この場合、ページネーションが機能しないので、不適切

BACK