WordPress: get category posts from current post

This code snippet gets the one of the category that is linked to the current post, and then print the url link to the posts under this category.

<?php
	$categories = get_the_category( $post->ID );
	$cateId = 1; $cateName = '';
	$cateSize = sizeof($categories);
	if ($cateSize > 0) $cateId = $categories[0]->cat_ID;
	$catquery = new WP_Query( 'cat='.$cateId.'&posts_per_page=10' );
?>
<?php while($catquery->have_posts()) : $catquery->the_post();?>
	<li>
		<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
	</li>
<?php endwhile;?>

Search within Codexpedia

Custom Search

Search the entire web

Custom Search