Manually define to show full post or excerpt on your homepage

January 23, 2009 · Print This Article

Do you use excerpts or full posts on your blog excerpts?

Personnally, I think they’re both good.

The only problem is that you can’t, by default, use both excerpts and full posts on your blog homepage.

Here’s a code to do it.

On your index.php file, replace your current loop by this one:

 

<?php if (have_posts()) :
while (have_posts()) : the_post();
$customField = get_post_custom_values("full");
if (isset($customField[0])) {
//Custom field is set, display a full post
the_title();
the_content();
} else {
// No custom field set, let's display an excerpt
the_title();
the_excerpt();
endwhile;
endif;
?>

On the code above, the default is excerpts. When you want to show a full post on your blog homepage, simply edit the post and create a custom field named full and give it any value.


Your choice for site templates and wordpress themes

Comments

One Response to “Manually define to show full post or excerpt on your homepage”

  1. acepek on May 5th, 2010 2:18 pm

    Thanks for the useful code! I think you were missing a right curly bracket before the endwhile; though. I’ve added it to the theme of my site, tested it, and it worked great. I simplified it a bit by moving the title call before the if statement. Here is the code I used:

    have_posts()) : $recentPosts->the_post(); ?>

    <a href=”” rel=”bookmark”>

    Thanks again!

Got something to say?

You must be logged in to post a comment.