我已经创建了一个页面,称为新闻,我正在使用博客页面。我在标题(设置为背景图片)中插入了一张图片作为精选图片,但显示的内容为最后博客帖子的精选图片。我怎么能强迫的WordPress从博客文章使用特定页面,而不是的缩略图的特色形象?自定义精选图像作为标题博客页
更具体地讲,这里是我的代码(header.php文件):
<?php if (has_post_thumbnail($post->ID)): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail');
$image = $image[0]; ?>
<?php else :
$image = get_bloginfo('stylesheet_directory') . '/images/fullscreen.jpg'; ?>
<?php endif; ?>
<header style="background-image: url('<?php echo $image; ?>')" > ... </div>
分享你试过的代码 –
你应该检查背景图片,它是如何设置的?通过css或者''尝试首先显示它是如何显示的,然后你可以使用硬编码页面id或者slug来获取特定页面的精选图像,并且你可以通过echo'get_the_post_thumbnail($ post - > ID,'thumbnail'); '它会用''标签打印html。 – Noman