Enhance your custom theme – Part 2

Final Step: Display post excerpts instead of full text

If we go back to our PSD, you’ll see that our index.php listing posts, displays post excerpts with a read more link. There are 2 ways to achieve this.

1. Manually insert read more links
This option is very handy when you’re not sure if blog posts will always be very long. If you’re building a site for a client, showing them how to add a read more tag using the WYSIWYG is very simple and they may appreciate the option of using read more only at certain times.

2. Use excerpts instead
If you are convinced that all posts need to show excerpts, then you can use the_excerpt() to display the blog post in your index.php and archive.php.

When you do this, you’ll notice that WordPress sets a number of characters as excerpts and adds […]. I personally, dislike this and so I simply add the following code to my functions.php files.

//Remove ellipses from excerpt

function blm_custom_excerpt_more($more) {
return '<br /><a href="'. get_permalink() .'">Read more &raquo;</a>';
add_filter('excerpt_more', 'blm_custom_excerpt_more');

//Modify the excerpt length

function blm_custom_excerpt_length($length) {
return 50;
add_filter('excerpt_length', 'blm_custom_excerpt_length');

The code snippet above replaces the […] with a break tag and a read more link. You’ll notice that there’s also a second function that allows you to modify the length of the excerpt. Changing the number 50 to whatever you want will simply modify the length.

Try both methods and see which one your prefer.

I’ve chosen the first method and you can see my final site here and download the theme files.

Comments are closed.