<?php
if(($cats = get_the_category( $post->ID ))){
$catID = array();
foreach ( $cats as $cat ){
$catID[] = $cat->cat_ID;
}
$wp_query = new WP_Query();
$args = array(
'post_type' => 'post',
'post__not_in' => array( $post->ID ),
'post_status' => 'publish',
'category__in' => $catID,
'posts_per_page' => 4,
'order' => 'DESC'
);
$wp_query->query($args);
if($wp_query->have_posts()){
?>
<!-- 出力部分 -->
<p><a href="<?php echo get_permalink(); ?>">
<?php the_title(); ?></a><br>
<?php the_excerpt(); ?></p>
<!-- 出力部分 -->
<?php
}
wp_reset_query();
}
?>