简体   繁体   English

内联PHP If语句返回背景图像样式之外的url

[英]Inline PHP If statement returns url outside of background-image style

Not sure where I've gone wrong? 不确定我哪里出错了? Researching this has provided me with not solutions. 研究这个问题并没有提供解决方案。

<?php echo ( has_post_thumbnail() ? 'background-image: url('. the_post_thumbnail_url() .');' : 'height: auto;' ); ?>

This is what I see returned in the browser. 这是我在浏览器中看到的返回内容。

<div class="image" style="//192.168.50.4:3000/wp-content/uploads/2017/07/rns-placeholder.pngbackground-image: url();">

the_post_thumbnail_url() outputs value, not returns it. the_post_thumbnail_url()输出值,但不返回值。

You need to use get_the_post_thumbnail_url() instead: 您需要使用get_the_post_thumbnail_url()代替:

<?php echo ( has_post_thumbnail() ? 'background-image: url('. get_the_post_thumbnail_url() .');' : 'height: auto;' ); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM