【发布时间】:2014-05-23 15:55:40
【问题描述】:
我正在创建一个 Wordpress 主题,它将所有页面显示为一个页面上的部分,并且菜单滚动到每个部分。我希望用户能够为每个页面设置一个独特的背景(这将是页面的特色图像)。但我发现,当用户为一页设置图片时,它会成为所有页面的背景图片。
如何调整我的代码,以便用户可以为每个页面设置唯一的背景图像?下面是我创建所有页面并将它们显示在一个页面上的代码:
<?php $pages = get_pages(array('sort_column' => 'menu_order'));
foreach ($pages as $page_data) {
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
$slug = $page_data->post_name;
//get url of featured image
$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true);
$thumb_url = $thumb_url_array[0];
//check if page has featured image
if ( has_post_thumbnail() ) {
$featured_image = $thumb_url;
}
else {
$featured_image = '';
}
echo "<section id='$slug' class='main fullscreen'>";
echo '<article class="main parallax" style="background:url(' . $featured_image . ') 50% 0 repeat fixed;">';
echo $content;
echo '</article>';
echo "</section>";
}
?>
【问题讨论】:
标签: php arrays wordpress background-image