WordPress.org

Ready to get started?Download WordPress

Forums

Page Background won't display in Posts page only (6 posts)

  1. atotalpirate
    Member
    Posted 1 year ago #

    Every other page is fine but when you go to a post's page the background.
    jholway.com is the site.

    Here is a blog post (with no background)

    I am using a bit of PHP that has the background images change when you refresh the page but I can't understand why it works everywhere but there.

    Here's the php:
    <?php
    $bg = array('bg-01.jpg', 'bg-02.jpg', 'bg-03.jpg', 'bg-04.jpg', 'bg-05.jpg' ); // array of filenames

    $i = rand(0, count($bg)-1); // generate random number size of the array
    $selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen
    ?>

  2. JarretC
    Member
    Posted 1 year ago #

    Can you pastebin.com the whole code that deals with changing the background image? From looking at your source code it looks like you might just have the image URL misconfigured.

    Also I noticed on the post page that global.css cannot be found.

  3. atotalpirate
    Member
    Posted 1 year ago #

    Here's i picked up the background changing code also the global stylesheet is only needed for the js slider on the frontpage.

  4. JarretC
    Member
    Posted 1 year ago #

    And the code you have in your header.php is the exact piece of code listed on that tutorial in the second piece of code?

  5. atotalpirate
    Member
    Posted 1 year ago #

    Yes except the paths to the images are correct. The images work fine and the php seems to work fine on every page but a specific posts page.

  6. JarretC
    Member
    Posted 1 year ago #

    Where do you have the images stored for the backgrounds? What is the directory structure?

    If you go into your source code for a blog post using Chrome Developer Tools, you'll see the following listed in the <head> section

    html{
    	background: url(../../../../images/bg-02.jpg) no-repeat center center fixed;
    	etc etc
    }

    If you add an additional ../ to the above URL structure the background image displays. So its just a matter of determining where the images are being stored and then echoing out the php to look in that location whether you're on the home page or a post page.

Topic Closed

This topic has been closed to new replies.

About this Topic