Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

My php question of the week... display multiple random images

3stripe3stripe ✭✭
edited March 2006 in Vanilla 1.0 Help
I'm using Zenphoto on a mate's blog... going along nicely but there's not much help forthcoming from its forum

image

Can anyone help me to tweak this code - I've made a few changes to just show 1 image on my homepage - but I need another version of it to display 4 small images in my sidebar - all I can get it to do is show 4 version of the same image... any ideas?

I understand how the function works , but no idea how to loop it, or make it more oop or whatever you call it...

<!-- small random image --> <?php require_once('portfolio/zen/classes.php'); $zpimagesize = (isset($_GET['s']) ? $_GET['s'] : 95); $randomImage = getRandomImage(); $imageLinkURL = getImageLinkURL($randomImage); $imagesrc = $randomImage->getSizedImage($zpimagesize); $imagesrc = substr($imagesrc, 1); $imagesrc = "http://www.paulryding.com/portfolio" . $imagesrc; print "<a href='http:".$imageLinkURL."' alt='".$randomImage->getTitle()."'><img src='".$imagesrc."' class='mainimage' alt='".$randomImage->getTitle()."'></a>"; function getRandomImage() { global $_zp_current_image; if(db_connect()) { $random=query_single_row('SELECT zpimages.filename, zpimages.title, zpalbums.folder FROM zpimages INNER JOIN zpalbums ON zpimages.albumid = zpalbums.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) { return WEBPATH . "/www.paulryding.com/portfolio/" . urlencode($image->getAlbumName()) . "/" . urlencode($image->name); } ?>

Comments

  • I guess what I really need is to turn this into a resuable snippet I can insert in a page, instead of including the whole darn thing each time, and also the ability to choose how many images to show... puts on thinking hat
  • maybe i should bug a php forum instead? any good ones?
  • sitepoint.com has smart people
  • I think what you could do quite simply is expand upon the getRandomImage and pass it the number of random images you want it to output. This should then pass the image locations down to you which you can either just spit back out or throw into a small array which you can later parse into a specified format (4square layout, or a sidebar of some kind) for easier tinkering later. I probably should install this to muck about with when I have some spare time.
  • 3stripe3stripe ✭✭
    edited March 2006
    Zenphoto is pretty sweet, but as I mentioned, it's still in beta, so there's not really any proper support, and there's not much about in the way of hooks/plugins/extensions at the moment, especially if you're not a coder. A lot of people seem to be using it in conjunction with Wordpress, because there's still fuck all in the way of decent image galleries for Wordpress.

    This is the second time I've bolted Zenphoto onto Wordpress and it's getting easier - just need to combine the 2 admin panels now haha...

    The inline text editing (Flickr style) is pretty impressive!
  • Wonder how Swell handles images?
  • merging 2 admin panels? if it's all on the same site, why bother having 2 albums in the first place ? :P
  • Nah sorry didn't explain that well at all, my bad - I've only got 1 zenphoto installed - I was just meaning it would be nice if it could be an actual plugin for wordpress, then you could control all the options from inside the Wordpress control panel
  • Sweet, just got some code from the Sitepoint forum, cheers c-unit

    (is your name meant to read like something else?)
This discussion has been closed.