I know many of you utilize a plug-in for the excerpt (abridged) version of your post. For those who are not familiar, an excerpt is a shortened version of your WordPress post. A visitor will then click a “more” permalink or the title to read the rest of your article. Many visitors don’t know to click the titles to move forward, my wife just proved this to me.
Some WordPress themes support excerpts and allow you to use the EXCERPT box in WP-admin while others do not. What about short posts that don’t need the “more” links? All themes are different depending on the creator. With this simple bit of instruction, you can change any theme without the use of another plugin.
Some freebies are beautifully designed but customizing them can be a nightmare. I have covered “the basics” regarding WP function and templates in previous posts. In this writing, I want to focus simply on the loop. Everyone has regurgitated this information but I am going to give you the simple option of converting your homepage posts over to excerpts; henceforth, no matter what theme you are utilizing… you can make some simple changes and you have EXCERPTS on your homepage. It will stop making your visitors scroll a great distance just to view 5 or 10 articles on your homepage.
THE BASICS
About that “more” permalink. You add it to all of your posts with the
<?php the_content('read the rest of the story...'); ?>
You can style the text in the tag with your CSS.
<?php the_content('<span class="morelink">Click here to finish...</span>'); ?>
We are going to keep it very basic and utilize an easy to follow full example below. After you are done, you will have shortened your posts and made your homepage something less cumbersome. No more WordPress plugins for simple tasks. Here are a few things to keep in mind:
PSEUDO CODE
1_Code checks to see if there is an excerpt/more tag.
2_Show the excerpt and post a link (header plus more link if desired).
3_If none then show post in its entirety.
So how do we make this happen?
In your WP-admin locate the index.php (home.php) in your theme editor. Keep in mind that you may want to back them up in a .txt file on your desktop. If your theme has both, just copy and paste the corrected loop into both once you are done.
Now find the div that contains your post loop. In Kubrick it is “entry” but other freebie themes label it differently (post, etc.).
<div class="entry">
<?php the_content('Read the rest of this entry »'); ?>
</div>
You are going to change that code to:
<div class="entry">
<?php if (!empty($post->post_excerpt)) : ?> //checks to make sure the excerpt exists
<?php the_excerpt(); ?> //It exists so read it. The loop.<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to
<?php the_title(); ?>">Read the whole story »</a></p> //your built in "more link" if you desire. Not necessary.<?php else : ?>
<?php the_content('Read the rest of this entry »'); ?> //Reads the Posts
<?php endif; ?>
</div>
That is all there is to it. WordPress keeps dropping pieces of my code even with the CODE tags. If something is not working, please let me know. Thanks! Also, anything after a // is a removable comment. I know its commonsense, yet… Coding is poetry in motion! Let the Netizen be heard!
Tags: Excerpt, Functions, PHP, Theme, WordPress


Want Something Else?