Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Single.php - If post has content display content else do this? WordPress

  • SOLVED

On my single.php - the post might or might not have any content. If there is content, I want that to be shown. If not, I want either one of these two things happening depending on whether or not the post has any comments.

1- If there is comments, I want a text blurb saying "There are comments posted for the_title(); and you can read them below."
2- If there are no comments, I want a text blurb saying "There are no comments for the_title(); yet - be the first one to post them!"

I have posted my best attempt below (which obviously doesn't work) :).

<? if($content = $post->post_content ) {
the_content();
} elseif {
echo "There are comments posted for the_title(); and you can read them below.";
} else {
echo "There are no comments for the_title(); yet - be the first one to post them!";
} ?>

Answers (1)

2010-06-08

Oleg Butuzov answers:

<? if(trim($post->post_content) != '' ) {

the_content();

} else if ($post->comment_count != 0) {

echo "There are comments posted for".apply_filters('the_title', $post->post_title)." and you can read them below.";

} else {

echo "There are no comments for ".apply_filters('the_title', $post->post_title)." yet - be the first one to post them!";

} ?>


badnews comments:

Thanks for your help. It works great.