简体   繁体   English

使用反向拉伸时,背景图片未显示在wordpress的“新闻页面”上

[英]Background image not showing on wordpress 'news page' when using backstretch

I have used backstretch to switch bg image for each page on my wordpress site, all is fine except for my 'news page' (ie blog functionality). 我已经使用backstretch在wordpress网站上的每个页面上切换了背景图片,除了“新闻页面”(即博客功能)之外,其他一切都很好。 Even though I've identified and used the correct page ID, the script doesn't want to update it. 即使我已经识别并使用了正确的页面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>';
    }
?>

From this code, page 60 is displayed without a background image. 根据该代码,显示的第60页没有背景图像。 Do I need to write something specific for news/blog pages? 我需要为新闻/博客页面写一些特定的东西吗?

Any suggestions will be gratefully received. 任何建议将不胜感激。

You'll probably need to nest the whole thing inside a document.ready call, otherwise you're trying to initialise it before anything is ready. 您可能需要将整个内容嵌套在document.ready调用中,否则您将在所有准备就绪之前尝试对其进行初始化。

Try this: 尝试这个:

<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");';
    }
?>
});

Also check for any JS errors in your console that might be preventing it from running properly. 另外,请检查控制台中是否有任何JS错误,这些错误可能会阻止其正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM