<?php
$cur_post = $wp_query->get_queried_object();
$currentId = $cur_post->ID;
$post_cats = get_the_category($currentId);
foreach($post_cats as $post_cat):
?>
<h2><a href=”<?php echo get_category_link($post_cat->cat_ID);?>”><?php echo $post_cat->name; ?></a></h2>
<ul>
<?php
$cat_posts = get_posts(“category=”.$post_cat->cat_ID.”&exclude=”.$currentId.”&numberposts=-1&orderby=date&order=DESC”);
foreach ($cat_posts as $post) : setup_postdata($post);
?>
<li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
似た感じで、カテゴリー別一覧
<?php
$cats = get_categories(‘parent=0&hide_empty=0′);
foreach($cats as $cat) :
$desc_cats = get_categories(‘child_of=’.$cat->cat_ID);
$desc_cat_ids = array($cat->cat_ID);
foreach($desc_cats as $desc_cat){
array_push($desc_cat_ids, $desc_cat->cat_ID);
}
$desc_cat_ids_str = implode(‘,’,$desc_cat_ids);
$cat_posts = get_posts(‘category=’ .$desc_cat_ids_str.’&numberposts=5&orderby=date&order=DESC’);
if($cat_posts):?>
<h2><a href=”<?php get_category_link($cat->cat_ID) ?>”><?php echo($cat->cat_name); ?></a></h2>
<ul>
<?php foreach($cat_posts as $post): setup_postdata($post); ?>
<li><a href=”<?php the_permalink();?>”><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endforeach; ?>
