How I show manual excerpts on my category pages

WordPress how toOne item I’ve had on my todo list forever was to convert my category pages into rich unique resource pages that were worthy of being indexed. I don’t currently index my category pages, because they would not be that useful to a searcher.

So to evolve my category pages into rich and unique pages of value, this week I took a step towards that goal by adding manual excerpts to the page.

Manual excerpts, are hand crafted summaries of your posts, and a great way to avoid having duplicate content on your site.

Many blogs will show you how to update your home page with manual excerpts, I didn’t want to do that – I wanted to update my category and tag pages – which currently only show the post titles – with manual excerpts. But the process isn’t that different. So I rolled up my sleeves and got to work. If you are new to WordPress and making code changes, this may not be for you. But if you are comfortable using FTP to upload files (or have ssh access) and working with php code, keep reading … .

Step 1: Identify the file to make changes to. I make all my changes in a child theme. So first I had to locate the right file to copy from my parent theme to my child theme directory. Turns out that the file in question was archive.php of which there was already a copy of in my child theme directory because I am using the WP-PageNavi plugin. Note that this file also is used to show any of your archive pages, ie. author and tag pages, so keep in mind this change will update them as well.

The full path would be ../wp-content/themes/<child-theme>/archive.php

Swap in your theme name for “child-theme” above. I knew archive.php was the right file by looking at the code, it has a large if statement determining which text to show based on whether the archive was category, tags, etc… However if you are unsure which file to edit, read through the codex’s template hierarchy documentation.

Step 2: Locate the while loop that is walking through your posts and displaying them. Mine looks like:
<?php while (have_posts()) : the_post(); ?>
Your theme might be displaying the full post or post teaser, if so you should see a call to the the_content() function. My theme was just showing post titles in an unordered list, so all I had to do was to add
<?php the_excerpt(); ?>
prior to the closing li tag. If your code has the_content() you will want to replace that with the_excerpt().

Step 3: Upload your updated archive.php file to your server, and you are done!

the_excerpt() is a nice function in that if there is no manual excerpt available for the post, it will show the first 55 words of your post.

Next up is to show unique category descriptions for my category pages – this will also be a code change. Once I have done that I will remove the noindex tag from these pages.

A shout out to welcometowp.com’s post on manual excerpts. If you want to add a Read More link or set it up so only excerpts show, he has some code samples to help you do that. I tried them out – but I didn’t like the formatting of the read more link (it’s difficult to get it to show as part of the excerpt) – and I prefer having something show (the 55 words) rather than nothing at all. So in in the end, my code ended up being much simpler than his examples, but still wanted to provide it as a resource.

Note: archive.php governs all archive pages: tags, categories, date archive pages. If you only want to change the category page, change category.php instead.

READ LATER? CLICK TO DOWNLOAD THIS POST AS PDF.

About the Author Kathy Alice

Kathy Alice Brown is a traffic and conversion expert specializing in SEO, Copywriting and Facebook Ad Campaigns. In her spare time she loves to get outside.

Leave a Comment:

1 comment
Kathy Alice says July 1, 2012

Added the while loop code to make it clearer what to look for.

Reply
Add Your Reply