admin管理员组文章数量:1302332
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>';
}
?>
本文标签: functionsHide thumbnail on search results when thumbnail not setusing Oxygen
版权声明:本文标题:functions - Hide thumbnail on search results when thumbnail not set - using Oxygen 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741669223a2391500.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论