0

I have a question I'm using a theme where the header image changes in different pages of the page because is set like that. But the main header image stays in all the remain pages..

What I want to do is to randomize 2 main header images everytime you refresh the page but leave the other header images to the other pages...

I don't know if I explain myself wellb but I'm leaving the code here. It must me something really easy and if you check out the code, you'll understand what I'm talking about.

<?php
    //Define Header Logo
    $catImage = "img/vallelogo.png";
    if (is_page('994')) {
        $catImage = "wp-content/uploads/2013/03/logo_lacomercial.png";
    }
    if (is_page('1013')) {
        $catImage = "wp-content/uploads/2013/03/logo_lacomercial.png";
    }
    if (is_page('998')) {
        $catImage = "wp-content/themes/theme1965/images/logo_lafamosa.png";
    }
?>

I want the first image

$catImage = "/img/vallelogo.png";

along with another image I want to add to randomize in the whole website, but leave the other images to show in those specific pages. How do I add the other image and make those 2 main headers to randomize in the whole website?

  • 1
    Both Twenty Ten and Twenty Eleven allow what you're describing using a combination of the core custom header functionality (which allows randomization of available headers) and featured images for the headers of specific posts of pages. You might want to see if there's anything you can adapt from the way they implement this. – sabreuse Nov 16 '13 at 19:01
0

Try this:

<?php
    function array_random($arr, $num = 1) {
        shuffle($arr);
        $r = array();
        for ($i = 0; $i < $num; $i++) {
            $r[] = $arr[$i];
        }
        return $num == 1 ? $r[0] : $r;
    }

    $a = array('vallelogo.png', 'img2.png');
    echo '/img/' . array_random($a);
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.