• Resolved macart

    (@macart)


    Hi Guys, Trying to get this to work:

    https://demo.marcofolio.net/php_random_image_rotation/

    Not sure what Im doing wrong. Im coding this wrong, so can someone tell me the correct way. Thanks.

    Where Im placing it.

    <div class=”contentBanner”></div>

    My CSS for Div.

    }
    .contentBanner {
    height: 250px;
    width: 788px;
    float: left;
    background: #003 url(images/banner.png);
    margin-top: 10px;
    margin-bottom: 20px;
    }

Viewing 14 replies - 16 through 29 (of 29 total)
  • Thread Starter macart

    (@macart)

    I followed the instructions above, placing above the header and below the footer. Slammed same exact errors! Is this a 2.8.1 bug?

    Thread Starter macart

    (@macart)

    Thanks again for everyones help. Wondering if anyone can get the image rotation described above to work on 2.8.1, or is it just me.

    Thread Starter macart

    (@macart)

    Tried it again this am, got the same errors above and this one:

    function randnum() { // Range creates an array from a range (in this case 1 – 10) $b = range(1,10); // So the array looks like – array(1,2,3,4,5,6,7,8,9,10) shuffle($b); $r = array_values($b); echo $r[rand(1,10)]; }

    Open the wp-config.php file and check there’s no extra lines or spaces after the ?> at the bottom..

    You shouldn’t need the output buffering in this case, so is there a particular reason you believe it will help?

    In would help to know what is in this file and on that line.
    wp-content/themes/mytheme.php on line 785

    Most common cause of the headers not sent error is white-space where it shouldn’t be. Check the config file first, as this is a common culprit..

    Regarding image rotation, there’s ton of scripts for the job, you only need a PHP script, take you pick.

    There are more then enough users here that are capable of providing you with one, i’ve given you one of many examples of random images…
    If you search the forum you’ll find other example code..

    A more basic random number function.

    <?php
    $numbers = range(1, 10);
    $numbers = array_rand($numbers,1);
    print $numbers;
    ?>

    Or with non-numeric array items…

    <?php
    $input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
    $rand_keys = array_rand($input);
    echo $input[$rand_keys] . "\n";
    ?>

    Thread Starter macart

    (@macart)

    Removed output buffering.

    Nice Catch! wp-config.php did have a white space at bottom. Corrected that and uploaded. Added code again to functions.php, slammed same errors.

    Not sure how to find line 784 and 785? Page source is only 100 lines of code.

    Put your functions.php code into pastebin….
    https://wordpress.pastebin.com/

    Then post a link here.

    Thread Starter macart

    (@macart)

    NO ERRORS! With this functions.php code.

    <?php
    if ( function_exists(‘register_sidebar’) )
    register_sidebar(array(
    ‘before_widget’ => ‘<div class=”sidepanel”>’,
    ‘after_widget’ => ‘</div>’,
    ‘before_title’ => ‘<h3>’,
    ‘after_title’ => ‘</h3>’,
    ));
    ?>
    <?php
    function randnum() {
    // Range creates an array from a range (in this case 1 – 10)
    $b = range(1,10);
    // So the array looks like – array(1,2,3,4,5,6,7,8,9,10)
    shuffle($b);
    $r = array_values($b);
    echo $r[rand(1,10)];
    }
    ?>

    Thread Starter macart

    (@macart)

    sorry newbie mistake

    Thread Starter macart

    (@macart)

    NO ERRORS! But still not working.

    https://wordpress.pastebin.com/m163e1bf7

    Thread Starter macart

    (@macart)

    image_2.jpg will show up eventually if I refresh several times. The rest of the time, the area is blank.

    That’s because you need to match the ID’s in the CSS to the total amount of images… look at the example i gave before, note this bit…

    /* And so on up to 10 (assuming 10 is the limit) */

    #myimage-1 {
    background-image:url(images/rotate/image_1.jpg);
    }
    #myimage-2 {
    background-image:url(images/rotate/image_2.jpg);
    }

    You need 10 of those if you have 10 images to rotate…. here’s the next 2 as an example..

    #myimage-3 {
    background-image:url(images/rotate/image_3.jpg);
    }
    #myimage-4 {
    background-image:url(images/rotate/image_4.jpg);
    }

    Right now that function is producing a number from 1-10, so you need to account for each instance…

    Or reduce the total amount it randomises.. (the 2 occurances of “10” in the function code).

    Thread Starter macart

    (@macart)

    My Bad. Thanks very much for all the help!

    Thread Starter macart

    (@macart)

    Working perfectly! Thanks again

    You’re welcome.. ??

    If it’s not flexible enough or not quite what you want we can always modify it..

    ??

Viewing 14 replies - 16 through 29 (of 29 total)
  • The topic ‘Random Image’ is closed to new replies.