Many WordPress themes are setup to display their category pages in the same format as your blog’s homepage, making your categories useless to some. This can cause duplicate content problems, as well as making your categories difficult to avoid. If this isn’t the case for you, then your theme is probably instead setup to just display a post excerpt for each post on your category page. I’ve never been a fan of this either, as this format strips your post of links/styles and doesn’t give you control over how much of the post to display.

Instead, I’ve always liked the idea of showing only the post titles on your category pages. If you are good at making post titles, this should help someone navigating your categories to find what they are looking for.

First, you’ll want to open your archive.php file and find the post loop. It usually starts with this code (or something similar):

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

You’ll want to delete everything from that code down to the end of the loop, which usually ends with this:

<?php endif; ?>

Now, you’ll want to replace the post loop code with the following slightly different code loop:

<?php $temp_category = single_cat_title('',false); if (!empty($temp_category)){ // give index ?>
<h1><?php single_cat_title(); ?></h1>
<p><?php echo(category_description(the_category_ID(false))); ?></p>
<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li><br>
<?php endforeach; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php }else{ // give details or single post ?>
...... code for normal post overview
<?php } ?>

And you’re done! You can add<li>, <ol>, and whatever else as needed, and then style your archives page in your stylesheet to get the look you’re trying to achieve.

Kyle Eslick is WordPress enthusiast who took his passion for WordPress to the next level in 2007 by launching WPHacks.com as a place to share hacks, tutorials, etc. Follow Kyle on Twitter @KyleEslick!

  1. Ken says:

    Just wanted to let you know that the code blocks on this post did not come through on my RSS feed.

  2. Richard H says:

    Kyle,

    I’ve seen the “title only” approach in use around the blogosphere and have been considering going that route. But…

    What do you think about including the “Optional Excerpt” below the title if kept to a limited amount of text? Perhaps even different text than the post itself?

  3. Darren says:

    THANK YOU! I’ve noticed something similar on the premium themes and have wondered how to do this. This is great!

  4. Kyle Eslick says:

    @ Ken – Thanks for the heads up on this. What feed reader are you using? I’ve checked in 3 different readers and the code showed up fine.

    @ Richard – I’m okay with that. I think it is really a preference thing. As long as you aren’t using full posts you should be good to go. On some sites I will use full posts but prevent the archives from being indexed.

    @ Darren – Glad you found it useful!

  5. Llama Money says:

    On some sites, I actually get some SE traffic to my category pages. I don’t want to de-index them because of that, so I stick with excerpts. They don’t take up too much space compared to just titles anyway.

  6. Ricardo Dias says:

    I use full post on home page and excerpt on category pages.

    This is very easy. If your template doesn’t have this by default just go to archive.php and replace tags “the_content” for “the_excerpt”, and your done!

    You can read more at the WordPress Codex.

  7. JP says:

    I have been looking for a code like this for some time. Thank you very much for the help. One quick question. When I put the code in, the post titles only list five at a time, and then allows users to press next entries to see more post titles. Is there a way to simply list all of the post titles on one page?

  8. crocodile says:

    THANK YOU! I’ve noticed something similar on the premium themes and have wondered how to do this

  9. blacksea says:

    This is great thanks

Trackbacks/Pingbacks »

  1. 100+ Killer Wordpress Resources | Steffan Antonas’ Blog says:
  2. Wordpress Tips and Tricks | Theme Heven says: