How to make category pages display post excerpts

By Daniel Scocco

Category pages, just like search results or archives, are usually used for navigation purposes. Considering this fact it would make no sense to display full posts on those pages since the reader needs to be able to skim through a larger number of posts to decide what he wants to read.

If your WordPress theme is currently displaying full posts on the category or archive pages below you will find how to change it, showing only the post excerpts or even the post titles.

First of all you need to locate the file inside your theme folder that is managing the category, archives and search pages. Most WordPress themes have that information inside the archive.php or archives.php file.

The file will look more or less like this:

<?php if (is_category()) { ?>
<h2 class='archives'>Archive for the '<?php echo single_cat_title(); ?>' Category</h2>
<?php }
elseif (is_day()) { ?>
<h2 class='archives'>Archive for <?php the_time('F jS, Y'); ?></h2>

Once you find the file you will need to find where the Loop starts, usually with the following line:

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

The information contained inside the Loop will govern the structure of the posts inside the mentioned pages (categories, archives, search results and so on). A couple of lines after the beginning of the Loop you will find the argument that includes the full posts on those pages:

<?php the_content(__('Read more »'));?>

In order to display the post excerpts you will need to substitute that line with the following:

<?php the_excerpt() ?>

If you want to display only the post titles (should be considered if you have a large number of posts on every category or on the archives) you can just eliminate that line altogether.

Finally, you may also want to remove the meta data (author, date or comments information) from those pages, which should be listed right after the post title or after the content line.



Related Articles

Please install the YARPP plugin

Share

30 Responses to “How to make category pages display post excerpts”

  • Keith Davis

    Daniel
    Short, sweet and to the point… just what I needed.
    Great to see the code displayed with easy steps for the php phibic like me!

  • Daniel

    Thanks for being the brains trust!

  • CreativeUnit

    Thank you for posting this!!!

  • Adam Pieniazek

    That code did not come through correct:

    a href=”?php the_permalink() ?>” rel=”bookmark”>Read the full post</a

    add an open bracket < at the start and before the first question mark, also add an end bracket at the end.

  • Adam Pieniazek

    Nevermind, got it. Simply place the below code after the excerpt code:

    “<a href=”” rel=”bookmark”>Read more“

  • Adam Pieniazek

    Is there a way to include the read more link dave was talking about on excerpts without fuddling about with the tag?

  • Masdin

    Thank you very much for sharing

    It works well in my wordpress theme (Inove).

  • Bang Kritikus

    Thanks for your guides

  • I V Y O L O G Y

    Oh my god, THANK YOU!!! I was told I have to install a plugin and fiddle with this and that, but no! I don’t! Thank you SO much for the simple instructions, you rock.

  • PeterVk

    Thanks! Tip worked like a charm.

  • dave

    oops forgot to list the plugin for whoever might be interested…
    http://guff.szub.net/2005/02/26/the_excerpt-reloaded/

    the only thing is you need to get into code a wee bit…..

  • dave

    never mind…. i just found this really great plugin which does everything i want and more!

  • dave

    Just a quick question….. how do you change the […] at the end of the excerpt to “read more” or “see more” or anything instead of […] ?
    dave

  • liuxxir

    prevedburzhuy

  • Andrew Swihart

    Glad I use Textpattern so I never have to deal with an issue like this where you actually have to know some php to do such a simple thing.

  • Daniel

    Rich, at the very least I think your theme has on call for single posts and one for archives, categories and search results, could it be?

    If that is not in place you will need to create those manually on the theme files. Just check some themes that use that structure and replicate it.

  • Rich

    Excellent info. I found myself in the same boat as Rory in that the theme I use (Burvy from GFX) did not have separate calls for archives and categories. I’m not an expert, but it seems my theme uses the same post output whether it is single post, archive, or category selected. I tried to carve out an excerpt call in the index.php just for category pages with the info you give but I couldn’t get it to work.

    I was curious if a workaround was discovered for these situations when you worked with Rory?

  • Ajay

    Daniel, you should mention that a category.php in the theme is the best way to create the category pages. Alternatively, you can use the (is_category()) and if true display the_excerpt otherwise do the_content

  • Thilak

    Sweet Hack! I really hate to see long posts in archives. I use a plugin called Evenmore, which does this automatically

  • engtech

    Excerpts are a great practice. Here’s a good article on them:

    http://www.pearsonified.com/2006/11/wicked-wordpress-archives-in-one-easy-step.php

    One thing I’ve noticed is that if you’re using a feedburner feed with summaries it’ll use your excerpt instead of just cutting off the first 200 characters or so.

  • Daniel

    Rory, lets chat via Skype, the file must be there somewhere otherwise the category pages would not be loading hehe.

  • Rory

    I hit a roadblock straight away – I don’t have an archives.php!

    I have it in my themes folder, but it is not available on the Presentation page. Is it because I removed it from my sidebar?

    My (hidden) archives.php reads:

    Archives
    By month:

    By category:

    But I’m not sure if I edit that it will make any difference.

  • Madhur Kapoor

    Very nice tip Daniel .

  • Daniel

    I voted for Problogger.net myself, so no big deal 🙂

  • Rory

    Brilliant. Thank you for this.

    I wish I could convey how hard I’m kicking myself for not voting for you in those recent Web Awards. I didn’t vote for anyone, but I’m cursing now!

Comments are closed.