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!!!!
-
1What have you tried thus-far? You'll need to show effort on your part, not just your need for an answer.– ZachCommented Oct 23, 2012 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 KatalinskiCommented Oct 23, 2012 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 KatalinskiCommented Oct 23, 2012 at 20:18
Add a comment
|
2 Answers
Just check the raw post content without any filters:
if ( "" === $post->post_content )
{
the_post_thumbnail();
}
else
{
the_content();
}
-
-
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.– fuxia ♦Commented Oct 23, 2012 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.... Commented Oct 23, 2012 at 21:19
-
I am not sure I can follow. Could you try to edit your question to make that easier to understand?– fuxia ♦Commented Oct 23, 2012 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 Commented Oct 23, 2012 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();