• Hey, I am trying to convert a site I created/themed in another CMS to WordPress and there’s one little thing I’m not sure how to make happen.

    Our site uses a random background image that pairs up with a random header image (background1 & header1 or background2 & header2, etc). It’s important that the background matches the header image.

    The only caveat to that is if it is for a specific page relating to that background it will display ONLY the relevant background image and header image. Here’s how I have it coded for the current CMS I used for the site (WolfCMS):

    <?php $randarts = $this->find('/random-header-background/')->children(array());
    $randart = array_rand($randarts, 1);
    $rand = $randarts[$randart]; ?>

    This code brings in the background from the page itself:

    <?php if (url_match('/glorkian') OR url_match('/dino-run') OR url_match('/potato')){echo $this->content('background');}
            else {echo $rand->content('background');}
        ?>

    Now this brings in some css that is attached to each of those pages in a separate call similar to the_content() except in WP terms it would be like the_content(myBackground)

    The css looks like this:

    <style type="text/css">
     body { background: #121c36 url('/assets/background.png') repeat-x bottom center fixed; }
    </style>

    Now the header image is brought in using:

    <?php if (url_match('/glorkian') OR url_match('/dino-run') OR url_match('/potato')){echo $this->content('header');}
                    else {echo $rand->content();} ?>

    Is there a way to replicate this where if I page matches perhaps even a Tag (ideally) or a page url specifically it calls in X background & header image, else it will bring in a random background & header image?

    If you want to see an example of how it works check out pixeljam.com. (Only the home page isn’t cached so the rest will likely not be very random).

  • The topic ‘Semi-Random Background and Header Pair’ is closed to new replies.