I’ve not tested this, but the following is the method you shoulduse. Don’t use query_posts
.
$cats_of_post= get_the_category();
if($cats_of_post){
$cat_id = (int) $cats_of_post['0']->term_id;
$related = get_posts(array(
'numberposts' => 5,
'category' => $cat_id,
'orderby' => 'post_date',
'order' => 'DESC',
'exclude' =>
));
global $post;
$temp_post = $post;?>
<div class="related-posts">
<?php if( $related ): ?>
<ol>
<?php foreach ($related as $post): ?>
<li>
<a href="https://wordpress.stackexchange.com/questions/57412/<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
<?php else: //No posts ?>
<p><?php _e('Sorry, no articles written under this category.'); ?></p>
<?php endif; ?>
<?php $post = $temp_post; ?>
</div>
<?php }//Endif no $cats_of_post