• Resolved DJD_79

    (@djd_79)


    Yeah, another one is going crazy.
    I’ve tried it over and over again, used this forum, the search button, Google, several plug-ins, but it just won’t work.

    For my website I use the theme Esther. In the photoframe is the image I want to change. Problem 1: I can find the picture in a folder, but I can’t find it in a php or css file.

    What I would like is (1) to change this image with every refresh. (2) People who come for “the first time” always have to see the same first picture.

    Problem 2: I allready have several photos in different folders (for the four galleries), so is it possible (3) to link from this folders or do I have to use another folder and upload a picture two times?

    Can somebody give a little help?

    Gr. Dennis, who is now going to bed, otherwise the PC is
    having a crash-core in flying, from six meters high…

Viewing 8 replies - 1 through 8 (of 8 total)
  • to start with, the image reference is in functions.php.
    you could probably find some php code to call a random image, even randomly from one of your other galleries.

    to show the same image first to every new visitor would probably require cookies.

    Thread Starter DJD_79

    (@djd_79)

    functions.php !!
    Yes I see it, thanks alchymyth/

    // No CSS, just IMG call
    define('HEADER_TEXTCOLOR', '');
    define('HEADER_IMAGE', '%s/images/dimple.jpg'); // %s is theme dir uri
    define('HEADER_IMAGE_WIDTH', 330);
    define('HEADER_IMAGE_HEIGHT', 293);
    define('NO_HEADER_TEXT', true );

    I’ll try to change %s/images/dimple.jpg in some code to link to a php file. In the php file I want to use the code to call some images. If that works ofcourse…

    I’ll be back

    Thread Starter DJD_79

    (@djd_79)

    Oke, I’m back…

    The picture on the website is blank now, so I know it’s the right piece of code I’m dealing with.
    I’ve got this, but it’s not working the way it should be. And it’s probably me πŸ˜‰

    // No CSS, just IMG call
    define('HEADER_TEXTCOLOR', '');
    define('HEADER_IMAGE', <?php include "banner.php"; ?> ; // %s is theme dir uri
    define('HEADER_IMAGE_WIDTH', 330);
    define('HEADER_IMAGE_HEIGHT', 293);
    define('NO_HEADER_TEXT', true );

    In banner.php is the code (lot’s of code to find, so thanks fot that already) but what need to be changed?

    Gr. Dennis

    the php tags are wrong, because the code is already surrounded by php tags, and a closing bracket is missing:

    define('HEADER_IMAGE', include (TEMPLATEPATH.'/banner.php')); // %s is theme dir uri

    as far as i understand, banner.php should return a string with the image url.
    banner.php code for instance (this returns the original image):

    <?php $img_path = get_bloginfo('template_url').'/images/dimple.jpg';
    return($img_path); ?>

    good luck, if in doubt, post the code of your banner.php here (use a pastebin if the code is longer) πŸ˜‰

    Thread Starter DJD_79

    (@djd_79)

    Thanks again.

    The site shows a random text now, so it’s almost ready, I think.
    The code for banner.php isn’t that long, so here it is:

    <?php
    /*
     * Name your images 1.jpg, 2.jpg etc.
     *
     * Add this line to your page where you want the images to
     * appear: <?php include "banner.php"; ?>
     */
    // Change this to the total number of images in the folder
    $total = "5";
    // Change to the type of files to use eg. .jpg or .gif
    $file_type = ".jpg";
    // Change to the location of the folder containing the images
    $image_folder = "wp-content/banner/";
    // You do not need to edit below this line
    $start = "1";
    $random = mt_rand($start, $total);
    $image_name = $random . $file_type;
    echo $image_folder . $image_name;
    ?>

    I tried to add the code for returning the string, but then only the
    picture dimple.jpg was shown.

    Why is it they’re still don’t understand each other?

    Thread Starter DJD_79

    (@djd_79)

    PS: I’ll add pictures in 1 folder to avoid problems, because the header has a different dimension as the gallery.
    Plus I can scale the files, so the size in kb isn’t the same.

    at the moment, the banner.php echos (outputs) the random img url to the browser.
    try and use ‘return’ instead of ‘echo’ (as in my example).
    i hope your image path is enough for wordpress to find the image.
    otherwise you can try and add ‘get_bloginfo(‘wpurl’)’ to the image folder:

    $image_folder = get_bloginfo('wpurl')."wp-content/banner/";

    Thread Starter DJD_79

    (@djd_79)

    alchymyth, you’re the best! That did the trick.

    I tried to add the wpurl thing, but then I got the blank photoframe again, so I now have the code from the first script. For readers having the same wish / problem, I copy the entire code again:

    define('HEADER_IMAGE', include (TEMPLATEPATH.'/banner.php')); // %s is theme dir uri

    The file banner.php

    <?php
    /*
     * Name your images 1.jpg, 2.jpg etc.
     *
     * Add this line to your page where you want the images to
     * appear: <?php include "banner.php"; ?>
     */
    // Change this to the total number of images in the folder
    $total = "5";
    // Change to the type of files to use eg. .jpg or .gif
    $file_type = ".jpg";
    // Change to the location of the folder containing the images
    $image_folder = "wp-content/banner/";
    // You do not need to edit below this line
    $start = "1";
    $random = mt_rand($start, $total);
    $image_name = $random . $file_type;
    return $image_folder . $image_name;
    ?>

    Many thanks to alchymyth

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Another One: Random Image in Header’ is closed to new replies.