カテゴリIDがたとえば186のときの記事に「関連する記事」を表示する、single.phpに埋め込むコード。
関連記事の表示は、JRelatedプラグインを使えばもっとすんなり導入できるので、今後使わないだろうけど、いつか使うようになったときのためのメモです。
<?php if (in_category(’186′)): ?><?php//for use in the loop, list 5 post titles related to first tag on current post$tags = wp_get_post_tags($post->ID);if ($tags) {echo ‘<div style=”background:#efefef; width:100%; clear:both; float:left; margin:15px 0″><h5 style=”margin:1px auto 1px 4px; font-size:10px;”>» 関連する記事</h5></div><ul>’;$first_tag = $tags[0]->term_id;$args=array(‘tag__in’ => array($first_tag),‘post__not_in’ => array($post->ID),‘showposts’=>5,‘caller_get_posts’=>1);$my_query = new WP_Query($args);if( $my_query->have_posts() ) {while ($my_query->have_posts()) : $my_query->the_post(); ?><?php if (in_category(’186′)): ?><li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></li><?php endif; ?><?phpendwhile;}wp_reset_query();}?></ul><?php endif; ?>
