Try
<?php
if ( '' == $post->content ) {
// do something special for blank content
} else {
the_content();
}
?>
Thread Starter
alastc
(@alastc)
Hi mdawaffe,
Thanks for replying, unfortunately I can’t get that to work.
Everything seems to match the ‘have content’ condition, although I’ve checked in the database, and a test post with no content shows none in the DB:
mysql> select post_content from wp_posts where id=’10’;
+————–+
| post_content |
+————–+
| |
+————–+
I’m not familiar with the -> notation, is that for selecting items from the database? In which case, wouldn’t it be:
if ( ” == $wp_post->post_content )
That doesn’t work either, so I guess not!
Any other possibilites?
Ah – that’s because there’s a typo.
<?php
if ( '' == $post->post_content ) {
// do something special for blank content
} else {
the_content();
}
?>
The -> is PHP syntax. It tells the program to look at the post_content property of the $post object. See the PHP docs.
Thread Starter
alastc
(@alastc)
Ah-ha! That worked a treat 🙂
Basically (for anyone else that wants to have posts with just excerpts and no link), you need something like this:
<?php if ( '' == $post->post_content ) {
// for posts without any content
?>
<h2 id="post-<?php the_ID(); ?>">
<?php the_title(); ?>
</h2>
<? } else {
// For posts with content, and therefore a link
?>
<h2 id="post-<?php the_ID(); ?>">" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></h2>
<p class="date">Posted: <?php the_time('jS F Y') ?>, in <?php the_category(', ') ?><?php edit_post_link('Edit', ', (', ')'); ?>.<!-- by <?php the_author() ?> -->
<?php }
// Finish heading bit, excerpt would go after this.
?>`
Thanks mdawaffe, I’ll look into that syntax as well, very useful. (Just couldn’t find it by putting “->” into a search engine).