Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

If post content exists, do not display featured image, if it does not exists, then display featured image or url. So, basically I want featured image to be displayed only if nothing else in post content to be displayed. Thanks!!!!

share|improve this question
1  
What have you tried thus-far? You'll need to show effort on your part, not just your need for an answer. –  Zach Oct 23 '12 at 20:12
    
I have this so far, it looks for the shorcodes and then displays them if found in the homepage, if not then featured image is displayed. Basically, I want featured image or anything else to be displayed if no other content, but if there is a content then I dont want image or url to be displayed, just a post content. –  Sergei Katalinski Oct 23 '12 at 20:18
    
Here is the code so far: <?php $pattern = get_shortcode_regex(); $matches = array(); preg_match_all("/$pattern/s", get_the_content(), $matches); echo preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $matches[0][0] ); ?> –  Sergei Katalinski Oct 23 '12 at 20:18

2 Answers 2

up vote 1 down vote accepted

Just check the raw post content without any filters:

if ( "" === $post->post_content )
{
     the_post_thumbnail();
}
else
{
    the_content();
}
share|improve this answer
    
Do I do this in loop or function.php? Thanks –  Sergei Katalinski Oct 23 '12 at 20:23
    
In a loop. You could encapsulate it in a function and move it to the functions.php but I think just using it as showed here will be easier to understand later. –  toscho Oct 23 '12 at 20:36
    
Your code works same as what I had: <?php $pattern = get_shortcode_regex(); $matches = array(); preg_match_all("/$pattern/s", get_the_content(), $matches); echo preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $matches[0][0] ); ?> . I just cant figure out how to display post content without featured image showing up? But, I do want the featured image to show up if nothing else in post. Thanks again.... –  Sergei Katalinski Oct 23 '12 at 21:19
    
I am not sure I can follow. Could you try to edit your question to make that easier to understand? –  toscho Oct 23 '12 at 21:30
    
Sorry 4 that, your code works great, it displays whatever is in the post content. For example if I have a post with the post content in it and there is also a featured image there too, I want some kind of code to ignore the featured image and only to display the post content; on the other hand, if there is nothing in post to be displayed, then I want that featured image to be displayed. This is all done in the front page (homepage), so there is always going to be something to be displayed no matter if its post or featured image....Thanks –  Sergei Katalinski Oct 23 '12 at 21:35

Inside the template file with the loop you'd want something like encased in PHP tags...

( empty( get_the_content() ) ) ? the_post_thumbnail() : the_content();
share|improve this answer
    
get_the_content() can be filled by plugins with extra strings and might not be empty even if the post_content is empty. –  toscho Oct 23 '12 at 21:00
    
That's a good point, I didn't think of that...thank you for the insight :) –  dmarges Oct 24 '12 at 14:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.