我使用backstretch切换我的wordpress网站上每个页面的bg图像,一切都很好,除了我的新闻页面' (即博客功能)。即使我已经识别并使用了正确的页面ID,脚本也不想更新它。
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://www.myurl.co.uk/wp-content/themes/name/bootstrap/js/jquery.backstretch.min.js"></script>
<?php
if(is_page(2))
{
echo '<script>$.backstretch("http://www.myurl.co.uk/wp-content/themes/name/img/bg_homepage.jpg");</script>';
}
else if(is_page(51))
{
echo '<script>$.backstretch("http://www.myurl.co.uk/wp-content/themes/name/img/bg_food_menu.jpg");</script>';
}
else if(is_page(60))
{
echo '<script>$.backstretch("http://www.myurl.co.uk/wp-content/themes/name/img/bg_whats_on.jpg");</script>';
}
else if(is_page(53))
{
echo '<script>$.backstretch("http://www.myurl.co.uk/wp-content/themes/name/img/bg_drink_menu.jpg");</script>';
}
else if(is_page(57))
{
echo '<script>$.backstretch("http://www.myurl.co.uk/wp-content/themes/name/img/bg_where_when.jpg");</script>';
}
else if(is_page(55))
{
echo '<script>$.backstretch("http://www.myurl.co.uk/wp-content/themes/name/img/bg_whats_on.jpg");</script>';
}
?>
从此代码中,显示第60页没有背景图像。我是否需要为新闻/博客页面撰写具体内容?
我们将非常感激地收到任何建议。
答案 0 :(得分:0)
你可能需要将整个事物嵌套在document.ready
调用中,否则你会在任何事情准备好之前尝试初始化它。
试试这个:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://www.myurl.co.uk/wp-content/themes/name/bootstrap/js/jquery.backstretch.min.js"></script>
<script>
$(document).ready(function(){
<?php
if(is_page(2))
{
echo '$.backstretch("http://www.myurl.co.uk/wp-content/themes/name/img/bg_homepage.jpg");';
}
else if(is_page(51))
{
echo '$.backstretch("http://www.myurl.co.uk/wp-content/themes/name/img/bg_food_menu.jpg");';
}
else if(is_page(60))
{
echo '$.backstretch("http://www.myurl.co.uk/wp-content/themes/name/img/bg_whats_on.jpg");';
}
else if(is_page(53))
{
echo '$.backstretch("http://www.myurl.co.uk/wp-content/themes/name/img/bg_drink_menu.jpg");';
}
else if(is_page(57))
{
echo '$.backstretch("http://www.myurl.co.uk/wp-content/themes/name/img/bg_where_when.jpg");';
}
else if(is_page(55))
{
echo '$.backstretch("http://www.myurl.co.uk/wp-content/themes/name/img/bg_whats_on.jpg");';
}
?>
});
同时检查控制台中可能阻止其正常运行的任何JS错误。