This article will show you a couple methods for showing excerpts from posts on the homepage, for searches and for archives. First I will show you the manual method of editing the WordPress theme code to accomplish this but I urge you to read on as their is a much more simple way of doing this.
First up the manual method using the WordPress the_excerpt() function. I will break this down into a few simple steps and show you how to modify what the function returns. The the_excerpt() function will replace the the_content() function which will be located in a few possible places. These places are home.php and category.php, if those files don’t exist in your template directory then you will only need to edit index.php. If for example category.php or home.php does exist then you can control if your posts on the homepage vs. searches and categories independantly which is a nice. If they do not exist you can still control this manually but it will take more coding which is not covered here, however an alternative is.
First open you home.php, category.php or index.php and use your browsers built in search function to search for “the_content”. You will want to select everything in between “<?php” & “?>” and delete it. I recommend copying the text to a notepad first before deleting it. You will then replace the line with “<?php the_excerpt(); ?>”.
Example
Before
<?php the_content(''.__('Read More »', 'sandbox').''); ?>
After
<?php the_excerpt(); ?>
This will look different depending on your theme but the idea is the same. Some themes are predictable and coded acording to the WordPress defaults while others just seem to go on their own path. I seriuosly think sometimes instead of a developer taking the time to learn how the WordPress code and functions work they would rather take skills they have learned in the past and force them onto WordPress and make them work. You will notice this too after editing several themes and each line of code is essentially the same but wrote completely different. You may see one developer write it all out in one line where another takes several. A great example of this is the Anvil theme. To change to Excerpts manually in the Anvil them you have to edit the index.php file and change
this
include( TEMPLATEPATH . '/thecontent.php');?>
with this
include( TEMPLATEPATH . '/theexcerpt.php');?>
Its almost like the dev didn’t know the function already existed and decided to re-write it all himself. I really don’t know but lets carry on.
You will now notice you have Excerpts but there is one little problem, or at least I see it as a problem. The default amount of words returned is 55 and I prefer 75 or even more. 55 words just isn’t enough to get someone hooked into your article. One other thing to note is if you are using the <more> tag in a post this should override the default excerpt values. At least that is according to the WordPress site as I have not tested it. The next thing I have an issue with is to read more you are left with the default “…” and this is often overlooked by readers. One reader may not see it and another less experiences reader may think it is the end of the article completely. Anyway lets carry on with step 2 which is controlling our excerpts.
Open Functions.php and at the bottom of the file add
<?php } function new_excerpt_length($length){return 75;} add_filter('excerpt_length','new_excerpt_length'); function new_excerpt_more($more) { global $post; return '<a href="'. get_permalink($post->ID) . '">' . '...More' . '</a>'; } add_filter('excerpt_more', 'new_excerpt_more'); ?>
You can change the value here from 75 to whatever number you wish and this will return the number of words returned for the excerpt. You will also notice the text “…More”, This is what I prefer readers to see when they get to the bottom of my excerpt. Its clear and stands out enough to show “Hey I’m Here Click ME” while not stealing the show. OK now I promised an easier way right? Well before we get on with that I want to cover one more thing. Thumbnails, that’s right where are the thumbnails in these excerpts? I wanna see thumbnails for my excerpts. As it turns out this is what lead me onto the “easier way”. I started searching for an easy way to show a thumbnail in the excerpt without a lot of editing required because I already had a bunch of posts I didn’t want to go back and edit and I didn’t want to make any major edits to my themes since #1 I change them often currently and #2 I don’t want a future update to break everything. This is how I found a plugin called “Thumbnail for Excerpts”. This plug is great, it will do the excerpts for you and it allows you to choose where they are shown (i.e. homepage, categories, search). The only thing I didn’t like was that it was defaulting to showing 55 words again. It even overrode my settings that I put into the Functions.php theme file. I found a simple solution though and here it is, Under Plugins click on Editor on the left side. Now from the drop down select Thumbnail for Excerpts. Find
$excerpt_length = 55;
Replace with
$excerpt_length = 75;
Or whatever you prefer.