我试图根据访问哪个内页来设置不同的页眉背景图片。现在,我对所有内部页面都有相同的图片,并且需要更改php代码以使其有条件。就像在联系人页面上的im一样,1.jpg被设置为标题img。如果在服务页面上,2.jpg被设置为标题img等,你就明白了。 以下是本WP主题即时试图提高一个朋友发现PHP代码IVE:每个WordPress页面的自定义背景图片?
<div class="bgtop">
<?php
//display featured image if one exists
$featimage = get_bloginfo('stylesheet_directory') . "/images/pageheader.png";
if ((has_post_thumbnail($post->ID))&&(!is_single()&&(!is_category()))){
$image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail');
$featimage = $image[0];
}
?>
<div class="pageheader" style="background: url(<?php echo $featimage; ?>); background-position: center top;">
<div class="centermenu">
<div class="pagelogo">
<!--<a href="<?php bloginfo('home'); ?>">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/indexlogo.png" alt="logo" />
</a>-->
</div>
我在PHP不好,并尝试了几个小时,找到方法来添加该标题BG图片取决于访问页面。不知道我卡住.. – rid
根据图像/页面的数量,你可能会更好使用CSS。 –
根据页面添加不同的类或id到body标签,并使用css执行此操作 – Rooster