WordPressで特定のカテゴリに属する最新記事を、子カテゴリ名とサムネイル付きで表示します。
<dl> <?php $cat = get_the_category(); $catname = $cat[0]->cat_name; $catslug = $cat[0]->slug; $current_cat = ''; foreach ( $cat as $cat ) { if ( ! $current_cat || cat_is_ancestor_of( $current_cat, $cat ) ) { $current_cat = $cat; } }; ?> <?php $categorys = array(40); for ($i=0; $i<count($categorys); $i++) : ?> <?php query_posts('showposts=6&cat='.$categorys[$i]); if (have_posts()) : while (have_posts()) : the_post(); ?> <dd><a href="<?php echo get_category_link( $current_cat ); ?>"><?php echo $catname; ?></a> <a href="<?php the_permalink(); ?>"><?php $image_id = get_post_thumbnail_id(); $image_url = wp_get_attachment_image_src($image_id, thumbnail); ?><img src="<?php echo $image_url[0]; ?>">></a></dd> <dt><a href="<?php the_permalink(); ?>"><?php the_time('Y/m/d'); ?><?php the_title();?></a></dt> <?php endwhile; ?> <?php else: ?> <dt>無し</dt> <?php endif; ?> <?php endfor; ?> </dl>