Show Post Titles on Category Page

Mon, May 25, 2009

Wordpress

Show Post Titles on Category Page

Show Post Titles on Category Page

Do you know the hardest part of wordpress themes (includes premium also) ? They don’t provide you a theme which displays your category page in post titles or in post excerpts. Category pages are for navigation purposes. It will be hard for the readers to check the full content. We should respect the reader’s time. Before trying this tutorial make sure you take a backup of the file you are going to work with.

If your WordPress theme is displaying full posts on the category pages you can find the tutorial for changing it, showing only the post excerpts or the post titles below.

Note : Most of the WordPress themes have those  inside the archive.php or archives.php file.

1. Converting Your Category Page To Display Post Titles :

Displaying post titles is normally considered when you have a large number of posts on every category.
First open the mentioned file and find the post
loop. It normally looks like this :

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

Now delete everything from that code to the end of the loop. It usually ends with this :

<?php endif; ?>

Replace the post loop code with the following different code loop for displaying only post titles :

<?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 ?>
…Here Code For Normal Post Overview
<?php } ?>

Thats all. Now save the file and check your new category page !
You can add tags like <li> or<ol> for ordering the posts with number or bullets and you can also style your page in your style sheet.

2. Converting Your Category Page To Display Post Excerpts :

The file is same here. The codes will be similar to this only.

<?php if (is_category()) { ?>
<h2 class=’archives’>Archive for ‘<?php echo single_cat_title(); ?>’ CATEGORY</h2>
<?php }
elseif (is_day()) { ?>

Check the loop in that file. It will be like this normally.

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

After some lines of codes, you will find a argument that includes the full posts on category pages.

<?php the_content(__(‘Continue Reading…’));?>

For displaying the post excerpts,  substitute the above line with the following line.

<?php the_excerpt() ?>

Note : If you don’t want to show the author, date or comments information then consider removing the meta data information from those pages. They are  listed right after the post title.

Author Bio:

This Guest Post is written by S.Pradeep Kumar from HellBound Bloggers. Pradeep is a Technical Blogger. He blogs about all the technical and security related topics at his blog. You can contact him anytime through his Orkut Profile.

Related posts:
  1. How to Create Custom Page Template in WordPress?
  2. How to remove Sidebar from a WordPress Page?
  3. Create Custom Sidebar in WordPress Blog

This post was written by:

- who has written 88 posts on Wordpress Tutorials.

I'm one of the Administrators of CHIDIMAR.com. I also own I'm Enk.. I'm 18 years old Blogger and Graphics Designer looking for Freelance work. You can follow me @enked

Contact the author

7 Comments For This Post

  1. Simon | Teenius Says:

    Awesome! Funnily enough, I’ve needed to change my category pages so that they only show excerpts, so I’ll test this out on my blog later on! Thanks! :D

    [Reply]

    S.Pradeep Kumar Reply:

    Simon. If you have more number of posts in each category consider trying the “Display Titles” tutorial instead ! It destroys the navigation problems ! ;)

    Cheers !

    [Reply]

    Enk. Reply:

    Yup.. I like Showing Post Titles instead of Post Excerpts on Category Page. But still depends on the Category and your Post Titles.. (they should be self explanatory ;) )

    [Reply]

  2. a_usman Says:

    Thanks for this tutorial… it is really useful.

    [Reply]

    S.Pradeep Kumar Reply:

    Glad it helped you ! :)

    [Reply]

  3. blinkky Says:

    You have gave very details tutorial here. keep it =)

    [Reply]

    S.Pradeep Kumar Reply:

    Cheers blinkky ! ;)

    [Reply]

    Enk. Reply:

    Glad you liked, blinkky ! :)

    [Reply]

  4. Alex | Asnio.com Says:

    Awesome post Pradeep, well done! I love styling my posts like this, and I think more people should do the same as well. You can get so much more content across this way.
    .-= Alex | Asnio.com´s last blog ..Maximize Your Earnings Through the Thesis Affiliate Program =-.

    [Reply]

    Enk. Reply:

    Yup, I also love the way posts look.
    Much more content on a single page. And Read friendly, and the page loads faster. :D

    [Reply]

    S.Pradeep Kumar Reply:

    Thanks Alex ! :)
    .-= S.Pradeep Kumar´s last blog ..Miles To Walk Before 2009 (Site Goals) =-.

    [Reply]

  5. G Says:

    Trying to insert it inbetween my div=”content” tags, giving me a t_string error at line 27 or 29.

    Here’s what categories.php looks like:

    Any ideas? Frustrating!
    .-= G´s last blog ..99 Excuses & Exercise Ain’t One – Excuse #1 =-.

    [Reply]

    G Reply:

    doh can’t paste the code … nonetheless, did exactly as instructed but not working right for me – any idea what I may be doing wrong? Just want a simple category page that lists post titles instead of entire post.
    .-= G´s last blog ..99 Excuses & Exercise Ain’t One – Excuse #1 =-.

    [Reply]

    S.Pradeep Kumar Reply:

    Mr.G thanks for trying out our tutorial ! :)

    I think you tried to show the code here.. but it is not displaying.. that is ok.. can you send me your blog’s categories.php or archives.php file.. may I can tweak something there… :)

    BTW, does your blog have archives.php file ? If so, you should try this thing there only … categories.php is the alternate choice for archives.php ..

    Cheers ! ;)
    .-= S.Pradeep Kumar´s last blog ..Miles To Walk Before 2009 (Site Goals) =-.

    [Reply]

  6. sriganesh Says:

    nice tip, and this is my first visit to this blog. good going.

    [Reply]

  7. Ansar Says:

    Great pots,
    but how can i display my category list by alphabetic order.

    [Reply]

Leave a Reply