由于以下代码,有什么原因会发生这种情况吗?所显示的只是变量,即图像。
<?php $featured_image = the_post_thumbnail();?>
<?php if (is_page(7) || is_page(12))
echo '<div class="featured_image">' . $featured_image . '</div>'
?>
由于以下代码,有什么原因会发生这种情况吗?所显示的只是变量,即图像。
<?php $featured_image = the_post_thumbnail();?>
<?php if (is_page(7) || is_page(12))
echo '<div class="featured_image">' . $featured_image . '</div>'
?>
<?php
$featured_image = the_post_thumbnail();
if (is_page(7) || is_page(12)) {
echo '<div class="featured_image">' . $featured_image . '</div>';
}
?>
该函数本身与 img 相呼应: http: //codex.wordpress.org/Function_Reference/the_post_thumbnail
尝试:
<?php
if ( has_post_thumbnail() && (is_page(7) || is_page(12))) {
echo '<div class="featured_image">';
the_post_thumbnail();
echo '</div>';
}
?>
您看到的是 echo 函数的返回值。