カテゴリーも表示する新着一覧
<div id="news">
<h2 class="entry-title">What's New</h2>
<ul>
<?php
// ▽ポストタイプとタクソノミーを入力
$post_type = 'post';
$taxonomy = 'category';
// △
$args=array(
'post_type' => $post_type,
'post_status' => 'publish',
'posts_per_page' => 3,
'orderby' => 'date',
'order' => DESC,
'caller_get_posts'=> 1
);
$my_posts = get_posts($args);
foreach ($my_posts as $post) {
setup_postdata($post);
$post_title = $post->post_title;
?>
<li>
<span class='date'><?php the_time('Y年m月d日'); ?></span>
<?php
$terms = get_the_terms( $post->ID, $taxonomy );
if ( $terms && ! is_wp_error( $terms ) ) :
$draught_links = array();
foreach ( $terms as $term ) {
echo '<a class="' . $term->slug . '" href="' . home_url( '/' ) . $term->taxonomy .'/'. $term->slug . '">' . $term->name . '</a>';
}
endif;
$days=7; $today=date('U'); $entry=get_the_time('U'); $diff1=date('U',($today - $entry))/86400;
if ($days > $diff1) { echo '<img src="' . get_bloginfo('template_url') . '/images/new.gif" alt="New" />'; }
?>
</span><br />
<a href="<?php the_permalink();?>"><?php the_title(); ?></span></a>
</li>
<?php } ?>
</ul>
</div>