Alrighty, another thing that comes up often for Wordpress, that I always forget how to do, is very similar to what I posted previously about excluding certain categories. This is listing a certain amount of titles, we’ll say 5, on the front page of the site. Below is the code for doing that.
1 2 3 4 5 6 7 | <?php query_posts('cat=X&showposts=5');?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div id="post-<?php the_ID(); ?>"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?> <?php endwhile; ?> <?php endif; ?> |
*In the code, on line 1, make sure to replace the ‘X’ with your category ID number.
Most of the work of this code takes place in line #1, where you specify the category you want to show and the amount of posts. The second most important piece of this code is line #5, the permalink and title code. This is how you’ll link to the actual posts that are listed. There’s more you can do with this I’m sure but this is the snippet of code I use most often.
6 People Have Bloviated
Lorissa | May 24
Excellent! Thanks for these Jen. I haven’t yet needed to do this, but no doubt it will crop up.
Pop Stalin | May 24
No problem lady!
David Airey :: Graphic Design Edinburgh :: | May 24
Likewise, I haven’t needed to use this code, but it certainly sounds useful!
Nice to know you’re still around, Jen.
Pop Stalin | May 25
Thanks David. I’ve been so busy lately that I just haven’t felt like being online.
Cristobal | Jul 22
and what about if i want to show the image from the post ?
plase save my life
thank you!
John | Dec 4
BwRNpq gfb7n0ghn60s9d7f34n30bnit5