semicolons

Mashup of posts on your Wordpress Homepage

I’m starting to think that idea of showing a bunch of full posts on homepage isn’t always the best solution to choose, so I think we can do something with it. The goal is clear – I want to show complete content of newest posts, and only excerpts of older writings. Wordpress engine offers 2 appropriate template tags that provide showing our expected result. You can find them somewhere in your main index template file.

  • the_content displaying contents of the current post within the Wordpress Loop
  • the_excerpt that shows only post excerpt, as a replacement for the_content() Template tag

In common use, you are able to show on your Wordpress homepage only complete post contents, OR only excerpt variants of your posts. Solution looks pretty simple, if you want to use it in your Wordpress template of choice, open up index.php file, and replace this (or code looking slighty similiar to this one):

<?php the_content(__('Read more...')); ?>

With the code listed below:

<?php if ( is_home() && ($post==$posts[0] || $post==$posts[1] || $post==$posts[2]) && !is_paged() ) : ?>
<?php the_content(__('Read more...')); ?>
<?php else: ?>
<?php the_excerpt(); ?>
<?php endif; ?>

Also, there’s one other thing that you have to add to your index.php file. It will give you a chance to be ok with the template order, by setting different limits of posts. First number for most-recent posts on your homepage, and the second for older ones that your readers see when they click Older Posts link (you can set that number somewhere within the Wordpress Dashboard).

Right before opening <div class=”post”> in the index.php ofyour Wordpress theme, paste the code added below. Of course you’re free to replace “7” with some other number.

24/11/09
  • home
  • rss
  • about
  • email
  • archive
  • random
  • copyleft © 2011 bart