Using WordPress’ Excerpt (the_excerpt) Creatively
Using WordPress’ the_excerpt function, or that box that says ‘Excerpt’ creatively isn’t something that too many people do. Why not? Not sure. But maybe that will change – the_excerpt can do so much so easily.
Display a quote from an article
Something that I used to do on Nometet was have a blog-like layout with a quote from the article displayed below the title. It’s something that gives the reader a quick peek at what’s in store in the article and well, looks pretty cool! What’s more, it’s easy to do – just pop a quote into the excerpt box when you’re writing a post. To implement your exciting new quote, just pop <?php the_excerpt(); /> into your theme’s files.
Display a random quote in your header/sidebar/footer
Now that we’re displaying random posts on our homepage (as shown above), next thing we can do the_excerpt is show a random quote on our header/sidebar/footer. Assuming you’ve filled out the Excerpt field for all your posts, the following code will display a random quote, with a link to the article:[php]<?php query_posts(array(‘orderby’ => ‘rand’, ‘showposts’ => 1));
if (have_posts()) : while (have_posts()) : the_post();
<a href=”<?php the_permalink(); ?>”>the_excerpt();</a>
endwhile; endif; ?>[/php]
Give your posts an introduction
Here’s an interesting one that I noticed in use on CatsWhoCode (see above)- on the homepage there’s a nice little intro about the post, but visit a post page and you’ll see the very same intro. It’s the same thing, using the_excerpt. Clever, eh? As it also splits your content up, you can pop in an advert in between the two (see it on this post). Just take out your opening section of your post and pop it into the Excerpt field. Then, using <?php the_excerpt(); ?>, implement it in your theme. Word of warning though, the excerpt won’t be shown in your RSS feed, so RSS readers could miss out on your nice little intro.
Avoid using custom fields for images
With the rise of magazine themes, the accompanying annoyance is filling out custom fields for images. This little trick will save some a couple of seconds – just pop the url of the image into the excerpt field (assuming your theme isn’t already using the excerpt) and with the code below, you can get around the need for custom fields:[php]<img src=”<?php the_excerpt(); ?>”
alt=”<?php the_title(); ?>” />[/php]
And that’s it
There we go. In this post, we’ve learnt some pretty awesome techniques, but why not share your favourite excerpt technique below?