I am using Oxygen to build a search results page. I am very new to CSS and PHP editing. I just floated an image right for the first time. So please forgive my ignorance.
I want to stop the thumbnail placeholder appearing in the search results when the post does not have a thumbnail/feature image set. I know that function that gets the image is <?php echo get_the_post_thumbnail_url(); ?>
but I have no clue how I would write the code to say if the post thumbnail is false (? maybe) then don't display the thumbnail.
Is anyone available to help me? I would be most appreciative.
I've copied the code I am using below and here's a screenshot of the Oxygen editor.
I am using this code in the Oxygen Template editor.
<div class='oxy-post'>
<a class='oxy-post-image' href='<?php the_permalink(); ?>'>
<div class='oxy-post-image-fixed-ratio' style='background-image: url(<?php echo get_the_post_thumbnail_url(); ?>);'>
</div>
<!--
<div class='oxy-post-image-date-overlay'>
<?php the_time(get_option('date_format')); ?> <?php the_title(); ?>
</div>
-->
</a>
<a class='oxy-post-title' href='<?php the_permalink(); ?>'><?php the_title(); ?></a>
<div class='oxy-post-meta'>
<!--
<div class='oxy-post-meta-author oxy-post-meta-item'>
<?php the_author(); ?>
</div>
-->
<!--
<div class='oxy-post-meta-comments oxy-post-meta-item'>
<a href='<?php comments_link(); ?>'><?php comments_number(); ?></a>
</div>
-->
</div>
<div class='oxy-post-content'>
<?php the_excerpt(); ?>
</div>
<!--
<a href='<?php the_permalink(); ?>' class='oxy-read-more'>Read More</a>
-->
</div>
I am using Oxygen to build a search results page. I am very new to CSS and PHP editing. I just floated an image right for the first time. So please forgive my ignorance.
I want to stop the thumbnail placeholder appearing in the search results when the post does not have a thumbnail/feature image set. I know that function that gets the image is <?php echo get_the_post_thumbnail_url(); ?>
but I have no clue how I would write the code to say if the post thumbnail is false (? maybe) then don't display the thumbnail.
Is anyone available to help me? I would be most appreciative.
I've copied the code I am using below and here's a screenshot of the Oxygen editor.
I am using this code in the Oxygen Template editor.
<div class='oxy-post'>
<a class='oxy-post-image' href='<?php the_permalink(); ?>'>
<div class='oxy-post-image-fixed-ratio' style='background-image: url(<?php echo get_the_post_thumbnail_url(); ?>);'>
</div>
<!--
<div class='oxy-post-image-date-overlay'>
<?php the_time(get_option('date_format')); ?> <?php the_title(); ?>
</div>
-->
</a>
<a class='oxy-post-title' href='<?php the_permalink(); ?>'><?php the_title(); ?></a>
<div class='oxy-post-meta'>
<!--
<div class='oxy-post-meta-author oxy-post-meta-item'>
<?php the_author(); ?>
</div>
-->
<!--
<div class='oxy-post-meta-comments oxy-post-meta-item'>
<a href='<?php comments_link(); ?>'><?php comments_number(); ?></a>
</div>
-->
</div>
<div class='oxy-post-content'>
<?php the_excerpt(); ?>
</div>
<!--
<a href='<?php the_permalink(); ?>' class='oxy-read-more'>Read More</a>
-->
</div>
Share
Improve this question
asked Mar 19, 2021 at 3:17
Pat BirganPat Birgan
1
1 Answer
Reset to default 1This below if statement checks to see if there is a thumbnail in the post. If not, nothing will display.
<?php
if ( has_post_thumbnail() ) {
echo '<div class="oxy-post-image-fixed-ratio" style="background-image: url('.get_the_post_thumbnail_url().')"></div>';
}
?>