Display random pics on a website ?

Hi
I want to display a random pics from zenphoto gallery on my website, how i can do that ???

Comments

  • Websat-

    Does your website run Wordpress, as there is a nifty plugin for Wordpress that allows you to display photos called Zenshow. Otherwise, you may have to code a routine to grab the random images from the database and display them. I have a random function that works within Zenphoto. Let me see if it can modified to work in your scenario.

    Thinkdreams.
  • websat Member
    hi
    Thanks for your answer, my website don't use wordpress, i made it myself using php (includes)
  • Cool. You should share it on the forums so others may benefit from your code.

    :)
  • websat Member
    ok, the main page is index.php who include with a menu other page named page-name.inc.php, the code for index.php is here: http://test.websat-telecom.com/index.php.txt
    The code for the page where i want to have a random pic from zenphoto is here: http://test.websat-telecom.com/index.inc.php.txt

    thanks for your help
  • websat Member
    nobody can help me ???
  • Patience please websat. We all have jobs, and are busy. I'm working with some ideas, but I have to work around my work schedule (8-5 M-F) and my personal responsibilities. We are all here on a voluntary basis. Others on the forum are under the same constraints I'm sure. So in other words, it may take time to get an answer to you, but if I don't someone else may have a quicker answer.
  • And those two links listed above to the php code of your website are not valid right now.
  • websat Member
    Ok, no problems thanks for your answer and your help, the links are now here:
    The code for the index
    http://www.websat-telecom.com/index.php.txt

    The code for the page where i want to have a random pic from zenphoto is here: http://www.websat-telecom.com/index.inc.php.txt
  • I can probably give you a push in the right direction. Take a look at Zenshow, a plugin designed to pull random images from the Zenphoto DB within Wordpress. There is a function in the code that deals with random photos. You may be able to rework that code to your needs, as it is just a SQL query to the zenphoto DB. That would be my suggestion on where to start. You can obtain Zenshow from a link somewhere on the wiki.

    That should get you started.
  • websat Member
    thanks for your help, i try this code for random.php:

    <?php
    require_once('classes.php');

    $imageSize = (isset($_GET['s']) ? $_GET['s'] : 150);
    $randomImage = getRandomImage();
    $imageLinkURL = getImageLinkURL($randomImage);

    print "<img src='".$randomImage->getSizedImage($imageSize)."' alt='".$randomImage->getTitle()."'/>";

    function getRandomImage() {
    global $_zp_current_image;
    if(db_connect()) {
    $random=query_single_row('SELECT images.filename, images.title, albums.folder FROM images INNER JOIN albums ON images.albumid = albums.id ORDER BY RAND() LIMIT 1');
    $image = new Image(new Album(new Gallery(), $random['folder']), $random['filename']);

    return $image;

    } else {
    return false;
    }
    }

    function getImageLinkURL($image) {
    if (zp_conf('mod_rewrite')) {
    return WEBPATH . "/" . urlencode($image->getAlbumName()) . "/" . urlencode($image->name);
    } else {
    return WEBPATH . "/index.php?album=" . urlencode($image->getAlbumName()) . "&image=" . urlencode($image->name);
    }
    }
    ?>

    and put that in the page where i want to see the random pic:
    code
    <?php include("http://galerie.websat-telecom.com/zen/random.php"); ?>
    code

    it don't work, in the page the link url is false:
    http://www.websat-telecom.com/zen/zen/i.php?a=pi6alk-mast&i=Dsc05486.jpg&s=150

    the good url must be: http://galerie.websat-telecom.com/zen/i.php?a=pi6alk-mast&i=Dsc05486.jpg&s=150
  • websat Member
    ok, it's work now, thanks for your help..
  • Will a wordpress widget of zenshow be released ?

    I've designed one but i had to remove a line in the connect() function to allow the widget to be used.

    this one:
    header('Content-Type: text/html; charset=ISO-8859-1');
Sign In or Register to comment.