我正在尝试为每个wordpress页面添加不同的bg图像。 http://www.designstest.co.uk/print-quote
以下是我正在使用的代码:
<?php
$class = '';
if (is_page('print-quote')) {
$class = 'main_image_quote';
} elseif (is_page('case-studies')) {
$class = 'main_image_case';
} elseif (is_page('contact')) {
$class = 'main_image_contact';
} elseif (is_page('services')) {
$class = 'main_image_services';
} elseif (is_page('news')) {
$class = 'main_image_news';
} elseif (is_page('suppliers')) {
$class = 'main_image_suppliers';
} ?>
<div id="main_image" <?php if($class) echo ' class=' . $class . '"'; ?>>
和css:
#main_image {
background: url(images/SRPM-Home-Page-Background.png) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#main_image.main_image_quote {
background-image: url(images/SRPM-Print-Quote-Page-Background.png);
}
#main_image.main_image_case {
background-image: url(images/SRPM-Case-Studies-Clients-Page-Background.png);
}
#main_image.main_image_contact {
background-image: url(images/SRPM-Contact-Page-Background.png);
}
#main_image.main_image_services {
background-image: url(images/SRPM-Services-Page-Background.png);
}
#main_image.main_image_news {
background-image: url(images/SRPM-News-Page-Background.png);
}
#main_image.main_image_suppliers {
background-image: url(images/SRPM-Suppliers-Page-Background.png);
}
我哪里出错了?它没有做它应该做的事情:(
答案 0 :(得分:1)
你错过了双引号:
<div id="main_image" <?php if($class) echo ' class=' . $class . '"'; ?>>
应该是
<div id="main_image" <?php if($class) echo ' class="' . $class . '"'; ?>>