[Resolved] Rotating background fails – except in Edge

Home Forums Support Rotating background fails – except in Edge

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #273000
    Hans

    I use the following php in wp-head:

    
    <?php if ( is_home()  || is_front_page()) : ?>
    <img src='http://huppenbroich.de/wp-content/uploads/hintergrundbilder/rotate.php' id='ktgbild' alt=''>
    <?php endif; ?>
    

    This works fine in edge – but not in Chrome, Opera, Firefox. It doesn’t change the picture and works in an endless loop.

    rotate.php is a standard routine which worked fine in other installations with generatepress.

    This is my site.

    What might be the problem???

    GeneratePress 1.3.44
    GP Premium 1.2.94
    #273050
    Tom
    Lead Developer
    Lead Developer

    Not sure what rotate.php does, but I would do it this way:

    <?php
    $headers = array(
    	'http://yourwebsite.com/URL/TO/header1.jpg',
    	'http://yourwebsite.com/URL/TO/header2.jpg',
    	'http://yourwebsite.com/URL/TO/header3.jpg',
    	'http://yourwebsite.com/URL/TO/header4.jpg',
    );
    
    $random = $headers[ rand( 0, count( $headers ) -1 ) ];
    ?>
    <style>
    	body{background-image:url('<?php echo $random; ?>');background-size:cover;}
    </style>
    #273107
    Hans

    Hi Tom,

    unfortunately this is very uncomfortable as I change the background very often. Could you please have a look at rotate:

    
    <?php
    /*
    By Matt Mullenweg > http://photomatt.net
    Inspired by Dan Benjamin > http://hiveware.com/imagerotator.php
    Latest version always at:
    http://photomatt.net/scripts/randomimage
    */// Make this the relative path to the images, like "../img" or "random/images/".
    // If the images are in the same directory, leave it blank.
    $folder = '';
    
    // Space seperated list of extensions, you probably won't have to change this.
    $exts = 'jpg jpeg png gif';
    
    $files = array(); $i = -1; // Initialize some variables
    if ('' == $folder) $folder = './';
    
    $handle = opendir($folder);
    $exts = explode(' ', $exts);
    while (false !== ($file = readdir($handle))) {
    foreach($exts as $ext) { // for each extension check the extension
    if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
    $files[] = $file; // it's good
    ++$i;
    }
    }
    }
    closedir($handle); // We're not using it anymore
    mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
    $rand = mt_rand(0, $i); // $i was incremented as we went along
    
    header('Location: '.$folder.$files[$rand]); // Voila!
    ?>
    

    I really wonder what could be the reason.

    #273120
    Tom
    Lead Developer
    Lead Developer

    That script was last updated in 2003.

    You’re definitely better off going with a more modern approach.

    #273134
    Hans

    It seems to be a caching problem. The editors handle it differently.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.