【发布时间】:2015-04-01 23:28:48
【问题描述】:
是否可以使用我的 PHP 逻辑来显示 WordPress 帖子的特色图片作为 div 的内联背景图片?这是我的尝试:
<div class="rounding-image" style="background-image: url(
<?php
if ( $thumbnail == true ) {
// If the post has a feature image, show it
if ( has_post_thumbnail() ) {
the_post_thumbnail( $thumbsize );
// Else if the post has a mime type that starts with "image/" then show the image directly.
} elseif ( 'image/' == substr( $post->post_mime_type, 0, 6 ) ) {
echo wp_get_attachment_image( $post->ID, $thumbsize );
}
}
?>
)"></div>
这不会引发特定错误,而是在图像所在的位置显示)">。
【问题讨论】:
-
我猜 $thumbnail == false 在这里。你没有其他人可以处理这个案子。尝试简单地添加 else where $thumbnail == false 并回显一些东西,任何东西。如果这确实回显,您就知道如何处理它了。
标签: php html wordpress logic background-image