在背景图像样式之外内联 PHP If 语句 returns url

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

不确定我哪里做错了?对此进行研究并没有为我提供解决方案。

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

这是我在浏览器中看到的返回结果。

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

the_post_thumbnail_url() 输出值,而不是 returns 它。

您需要使用 get_the_post_thumbnail_url() 来代替:

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