Skip to content

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.

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]&lt;?php query_posts(array(‘orderby’ =&gt; ‘rand’, ‘showposts’ =&gt; 1));

if (have_posts()) : while (have_posts()) : the_post();

&lt;a href=”&lt;?php the_permalink(); ?&gt;”&gt;the_excerpt();&lt;/a&gt;

endwhile; endif; ?&gt;[/php]

Give your posts an introduction

fireshot-pro-capture-12-catswhocode_com-www_catswhocode_com_blog

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]&lt;img src=”&lt;?php the_excerpt(); ?&gt;”

alt=”&lt;?php the_title(); ?&gt;” /&gt;[/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?

Yay! 🎉 You made it to the end of the article!
Alex Denning

5 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Free WordPress (Portfolio/Personal Blog) Theme: Happy Go Try | WPShout.com
December 1, 2009 7:13 pm

[…] them!), just a couple of things to know. The text pulled on the front page – that’s the excerpt. The image used can be put in place as with Biblioteca, as the screencast shows (link if you […]

Epic Alex
July 8, 2009 2:51 pm

Does the tip "Display a random quote in your header/sidebar/footer" not create non valid code? the_excerpt outputs p tags, which is a block-level element, and as far as I understood it, that can't go inside an inline element, ie the link.

The same goes for avoiding custom fields, except here doesn't that also mean the scr attribute has p tags in it?

edouard
September 15, 2009 5:14 pm
Reply to  Epic Alex

oh yeah … cool trick to pass html validation .. that rocks, thx a lot

edouard
September 15, 2009 5:15 pm
Reply to  edouard

using the_excerpt_rss() is working I mean …

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!

5
0
Would love your thoughts, please comment.x

Most Searched Articles

Best JavaScript Libraries and Frameworks: Try These 14 in 2024

In this post, we look at the best JavaScript libraries and frameworks to try out this year. Why? Well, with JavaScript being available in every web browser, this makes it the most accessible programming language of ...

20 Best Free WordPress Themes for 2024 (Responsive, Mobile-Ready, Beautiful)

If you're looking for only the best free WordPress themes in the market for this year, then you're in the right place. We have more than enough such themes for you right ...

12 Best WordPress Hosting Providers of 2024 Compared and Tested

Looking for the best WordPress hosting that you can actually afford? We did the testing for you. Here are 10+ best hosts on the market ...

Handpicked Articles

How to Make a WordPress Website: Ultimate Guide for All Users – Beginners, Intermediate, Advanced

Many people wonder how to make a WordPress website. They’ve heard about WordPress, its incredible popularity, excellent features and designs, and now they want to join the pack and build a WordPress website of their own. So, where does one get ...

How to Start an Ecommerce Business: Ultimate Guide for 2024

Is this going to be the year you learn how to start an eCommerce business from scratch? You’re certainly in the right place! This guide will give you a roadmap to getting from 0 to a fully functional eCommerce business. ...