How To: Converting Your Category Pages to Display Post Titles

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.

Digg This | Stumble it |