How to Show Titles Only on a Wordpress Archive Page

November 20th, 2007 by Richard Cockrum

If you’re running Wordpress, how do you like your archive page? Do you like having complete post after complete post for page after page? Do you like just showing excerpts for each page?

I wanted to try something different. I wanted to show just the titles of the posts on each archive page because it looks cleaner and because it takes away another possible source of duplicate content on the blog. I also decided to add the number of comments for each post so readers can see which ones got the most response, the date published, and the author. Finally, I wanted all the posts to show up on one page.

I know there are plugins to do similar tasks, like Clean Archives and Clean Archives Reloaded, but neither of these did exactly what I wanted.

So, I got to learn a little more about Wordpress. First up was a little function called query_posts(). While this function can do a lot of things, the part I was interested in was it’s ability to change the page structure from one that was paged to including all the posts on one page. So, my first step was to call query_posts() before entering the loop on the archive page of my theme with the original query string (held in $query_string) and the parameter posts_per_page set to -1 (which tells wordpress to put everything on one page):

<?php query_posts($query_string . "&posts_per_page=-1"); ?>
<?php if (have_posts()) : ?>

The next step happens within the loop. This was mostly a matter of removing calls from the loop to show the content of the post. I also took the post titles out of headers and added the call to comments_number() to get the number of comments for the post.

<?php while (have_posts()) : the_post(); ?>
<div style="padding-bottom: 10px;">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a><?php echo ' - ' ?><?php comments_number('0 comments', '1 comment', '% comments'); ?><br />
<small><?php the_time('F jS, Y') ?> by <?php the_author() ?></small>
</div>
<?php endwhile; ?>

You can see the results on any of my archive pages. A good example is my beliefs archive page.

I’m still using Wordpress 2.2, so I don’t know if this will work on Wordpress 2.3 or higher, but it works for me and gave the results I was looking for. It shows you don’t have to be a Wordpress expert to make some nice customizations to your blog.

Popularity: 28% [?]

6 Responses to “How to Show Titles Only on a Wordpress Archive Page”

  1. John Says:

    The plugin SRG Clean Archives has served me well doing much the same thing.

  2. Richard Cockrum Says:

    Hi John,

    SRG Clean Archives is an excellent plugin for what it does. I would recommend it highly to anyone. What it does isn’t exactly what I wanted, though. It only works with date archives. The technique I describe here will work with date and category archives both. Second, I want to experiment with not having any post content on my individual archive pages. This lets me to do that.

  3. mahud Says:

    I’ve been thinking about removing the post content for the archives. I didn’t know about the query string. I might try it that way :)

    Currently, I use the Custom Query String plugin (It’s no longer supported but can be found in the author’s archives), which does the same thing listing the number of posts in the archives (-1 to list all posts), search results, etc. Also you can have them ascending or descending , ordered alphabetically and stuff like that. I also use 2.2, and I’m not sure if the plugin works for later versions of Wordpress.

  4. Richard Cockrum Says:

    Thanks for pointing the way to that plugin, mahud. I probably wouldn’t have done this if I had found that first. The Custom Query String plugin looks like it does much the same thing as query_posts(). Use it in conjuntion with the changes I made to the body of the archive template and you have the results I was looking for.

  5. Anurag Bhateja Says:

    Really helpful!!!! was finding this only!!! thanks a lot!!!!

  6. Rick Cockrum Says:

    You’re welcome, Anurag.

Leave a Reply