同じカテゴリー出力


<!-- 同じカテゴリーに属する記事の出力 -->
<?php if(has_category()) {
$cats = get_the_category();
$catkwds = array();
foreach($cats as $cat) {
$catkwds = $cat;
}
} ?>

<?php
$myposts = get_posts(array(
'post_type' => 'post',
'post_per_page' => '4',
'post__not_in' => array($post->ID), // 表示中の記事は出力対象から除外するため
'orderby' => 'rand'
));
if($myposts) : ?>
<aside class="mymenu mymenu-thumb">
<h2>関連記事</h2>
<ul>
<?php foreach($myposts as $post):
setup_postdata($post); ?>

<li><a href="<?php the_permalink(); ?>">
<div class="thumb" style="background-image:url(<?php echo mythumb('thumbnail'); ?>)"></div>
<div class="text">
<?php the_title(); ?>
</div>
</a></li>
<?php endforeach; ?>
</ul>
</aside>
<?php wp_reset_postdata(); endif; ?>