How to display excerpt and complete content in WordPress

Sun Dec 6, 2009, 1:38 am | Leave Comment



The question of “how to display excerpt and complete content in WordPress” has been asked probably more than we care to hear and answers given perhaps more than we care to listen. In one of the discussion forums that I have joined, a participant wanted to know how she could display excerpts of a post on her ‘Home’ page and that if the blog visitor wanted to continue reading, how she would attempt to code it so the visitor would be able to read the complete article.

The following is yet another attempt to go about the task. This is actually what I have implemented on my WordPress blog.

Conditions used
There are some conditions we have to use which are as follows:

is_home()
is_page()
is_category()
is_singular()

Algorithm used
If individual post has been clicked, display complete content
After the content is displayed, I then display
some messages

else display excerpt of the article and display a
click-able indication for continue reading…

<?php if (is_singular()) : ?>
	<?php the_content();  ?>

<?php else : ?>
	<?php the_excerpt();  ?>
	<strong><?php _e('<a href="'.get_permalink().'">
	Read More »'); _e('</a>'); ?></strong>

<?php endif; ?>


In addition, on the Home page, because I have several
posts  in the form of excerpts, I like to have Google
AdSense after the excerpts of the first post only and
after that no AdSense. I treat category and Home similar
and display AdSense after the complete content as well.

Therefore I give the following conditions:

If this is (single post or (first post and
(home or category)) and not page)
then display Adsense ads

<?php if (is_singular() || ($post==$posts[0]
&& (is_home() || is_category())) && !is_paged()) { ?>

	Here I display AdSense ads

<?php } ?>

I then like to display a line per postmetadata
defined in style.css to make the distinction (separation)
between excerpts.

<p class="postmetadata"></p>

Note
If you just want to display the complete content skipping the excerpt like some blogs do, then instead of all the conditions as stated above, you would just have the the_content() in your code.



Related Posts On Doable Finance dot Com

  1. How To Create A Blog In WordPress



Leave Your Comments!

Your email address will not be published, period.


*

Please follow Doable Finance dot Com Comment Rules.


Click on the left to read more similar articles.




 

 

 

 

Top Of Blogs Blog Top Sites Blog Flare Blog Top List Blog Top List
Top Blogging Top Blog Area On Top List My New Blog My Zimbio Blog Log Blogs Avenue