24 May 2007

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. < ?php query_posts('cat=9&showposts=5');?>
  2. < ?php if (have_posts()) : ?>
  3. < ?php while (have_posts()) : the_post(); ?>
  4. < div id="post-< ?php the_ID(); ?>“>
  5. < a href="< ?php the_permalink(); ?>“>< ?php the_title(); ?>
  6. < ?php endwhile; ?>
  7. < ?php endif; ?>

*if you’re going to copy and paste this code, make sure to take out all extra spaces.

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 Comments

  1. No. 1 John 12/04/07

    BwRNpq gfb7n0ghn60s9d7f34n30bnit5

  2. No. 2 Cristobal 07/22/07

    and what about if i want to show the image from the post ?

    plase save my life
    thank you!

  3. No. 3 Pop Stalin 05/25/07

    Thanks David. I’ve been so busy lately that I just haven’t felt like being online. :)

  4. Likewise, I haven’t needed to use this code, but it certainly sounds useful!

    Nice to know you’re still around, Jen. ;)

  5. No. 5 Pop Stalin 05/24/07

    No problem lady! :)

Tell Me What You Think

About Me

My name’s Jen; I’m a cynical, sarcastic, ex-drummer who is fond of dark humor. I've held way too many factory & retail jobs but finally found my calling one Christmas holiday in a dark, musty basement. I am now a CSS & XHTML web standards looney and can be found daily—when I’m not at my Mac—at the local fair-trade coffee shop buying an iced-soy mocha no matter the temperature.

I am also the owner of Pop Stalin Design specializing in CSS & XHTML web design as well as custom WordPress themes.