Template

How to show Recent Posts by Category in Wordpress

In my Ask-Nik.info blog I wanted to display at the front page all the recent posts but not ordered by date.

I wanted to display every of my categories by 3 posts each. I've searched a lot of plugins but none did the job for me.

So I searched about a day how to do it by myself.

I finally manage to write a front page template which does this job for me. If you take a look at the Ask-Nik.info blog you will understand what I mean.

Here is the code :

<?php get_header(); ?>
	<div id="content" class="narrowcolumn">


	<?php

		$all_categor = get_all_category_ids();
		foreach($all_categor as $cat) :
			$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
			query_posts('paged='.$page.'&showposts=3&cat='.$cat);


	?>

			<?php while (have_posts()) : the_post(); ?>
				<div class="post" id="post-<?php the_ID(); ?>">



Syndicate content