Random Thumbnail?

Hi,

I have ZenPhoto and WordPress installed. They work a dream :D

However, I'm running into problems displaying a random thumbnail on my sidebar in WordPress?

I've looked at and tried Hacks and Extensions found in this forum and site, but am none the wiser. Up til 2am on a work-night was not good :(

Can someone please hold my hand and help me along this treacherous path?

Many thanks.

Comments

  • Hate to bump, but any takers?

    I'm really racking my brain on this one.

    ZenPhoto is fully installed and working a dream, but I've had no such luck with the Random Thumbnail.

    Thank you.

    P.S Lost my password for 'invision', then found it again :d
  • acrylian Administrator, Developer
  • Thanks for the reply.

    I've looked there and seen these two parts

    `define('ZENFOLDER', 'zp-core');

    define('WEBPATH', 'zenphoto');

    require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");`
    and
    `$randomImage = getRandomImages();

    $randomImageURL = getURL($randomImage);

    echo "image
    $randomImage->getSizedImage(getOption('image_size')) .

    "' alt="random image"n" . $randomImage->getTitle() .

    '" />
    ';`

    Have already tried the above code before, but maybe I'm not using it right. Can you give me an example?

    So I have my sidebar my WP theme, which is used for my ZP also.

    How should I place the random thumbnail generator code into 'sidebar.php'?

    Thankyou.
  • hi the way I integrated my latest, and most popular images in my wp-sidebar (see: http://www.bertsimons.nl/zenphoto/) in this way;

    I make a php file called latest.php or in your case randomimage.php with content:

    `<?php $randomImage = getRandomImages();<br />
    $randomImageURL = getURL($randomImage);

    echo "image
    $randomImage->getSizedImage(getOption('image_size')) .

    "' alt="random image"n" . $randomImage->getTitle() .

    '" />
    ';?>`

    an place this in my zenphoto theme folder.
    now in my wp-sidebar I put (because calling zenphoto functions straigt away doesn't work)
    `

    <?php include("http://www.bertsimons.nl/zenphoto/?p=randomimage"); ?>`

    but what happens....

    in my sidebar i get the error

    `MySQL Query ( SELECT `zp_images`.filename,`zp_images`.title, `zp_albums`.folder, `zp_images`.show, `zp_albums`.show, `zp_albums`.password FROM `zp_images` INNER JOIN `zp_albums` ON `zp_images`.albumid = `zp_albums`.id WHERE `zp_albums`.folder!="" AND `zp_albums`.show=1 AND `zp_albums`.id != 199 AND `zp_albums`.id != 201 AND `zp_images`.show=1 ORDER BY RAND() LIMIT 1 ) Failed. Error: You have an error in your SQL syntax near 'show, `zp_albums`.show, `zp_albums`.password FROM `zp_images` INNER JOIN `zp_alb' at line 1`

    so i guess there's something wrong with the getRandomImages() function..
  • Zenphoto needs a bit more than your theme file to function, so just doing an include on it will not work. You need the
    `define('ZENFOLDER', 'zp-core');

    define('WEBPATH', 'zenphoto');

    require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");`
    code in your sidebar to setup zenphotos environment.

    Ov course `zenphoto` needs to be the folder where zenphoto was installed.
  • sbillard, those calls I already included.

    Other zenphoto functions , like most popular, latest images and taglist get embedded in the wp-sidebar without a problem as you can see on my site. except for when using the printRandomImages(); I get the mysql error
  • I really don't know what could be causing this. The following code is working as we speak on my test site testalbum-2.sbillard.org
    `<?php <br />
    define('ZENFOLDER', 'zp-core');

    define('WEBPATH', 'zenphoto');

    require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");

    header ('Content-Type: text/html; charset=' . getOption('charset'));

    ?>





    Test Index





    <?php <br />
    $images = getImageStatistic(6, "latest");

    foreach ($images as $image) {

    echo "
    n";

    $imageURL = getURL($image);

    echo '
    $image->getTitle() . '">image
    $image->getCustomImage(null, 44, 44, null, null, null, null, true) .

    '" alt="' . $image->getTitle() . "\"/>
    n";

    echo "
    n";

    }

    printRandomImages();

    ?>



    `

    Not integrated into WP, but maybe there is a conflict somewhere in that integration.
  • I get the following error when I plug that into my site :(

    `Warning: main(zenphoto/zp-core/template-functions.php) [function.main]: failed to open stream: No such file or directory in /home/michaelsiteuk/public_html/michaels/zenphoto/test.php on line 4

    Fatal error: main() [function.require]: Failed opening required 'zenphoto/zp-core/template-functions.php' (include_path='.:/usr/share/pear') in /home/michaelsiteuk/public_html/michaels/zenphoto/test.php on line 4`

    But there definitely is a 'template-functions.php' file in the zp-core folder :(

    I placed that code, on its own, into a file :
    www.mysite.com/myfolder/zenphoto/test.php

    and my WP is at :
    www.mysite.com/myfolder/wordpress/

    And still it won't work.

    Any ideas?

    Thank you for your time.
  • acrylian Administrator, Developer
    Ok, then the path to your zenphoto folder seen from WP would not be "zenphoto" but "../zenphoto".
  • The folder structure of my site was:

    Root folder (..testalbum-2/htdocs): contains the above index.php file
    zenphoto folders (..testalbum-2/htdocs/zenphoto) contains all the zenphoto files.

    Your test.php should probably be in the `michaels` folder.
  • sbillard, with your code the same..the first part to generate the latest images works, the randomimages functions returns the mysql error off which i've placed a screenshot here

    http://www.bertsimons.nl/zenphoto/albums/various/publicity-photos/Screenshot.png
  • I am at a loss, there is some kind of conflict in your setup. http://testalbum-2.sbillard.org/ does not get any errors, but then Wordpress is not involved at all.
  • just did a fresh install of zenphoto 1.1.5 together with a new database and using the default theme.
    so no wordpress involved and inserted the latest and random image code in the default theme.

    but..same error output from the printRandomImages()....

    as seen at http://www.bertsimons.nl/zenphototest/
  • acrylian Administrator, Developer
    Strange thing, I can't reproduce that with a clean 1.1.5 install, too. Maybe this is a PHP/MySQL-version problem? Which versions do you run? I have PHP 5.2.3/MySQL 5.0,41.
  • i just try and it works fine.

    But testing printRandomImages() i have seen thaht we can specify 'album' in $option.

    function printRandomImages($number=5, $class=null, $option='all')

    but after i see :

    case "album":
    $randomImage = getRandomImagesAlbum(); break;

    Where we can specify the album name ?

    Thanks.
  • acrylian Administrator, Developer
    You can't, it simply built to return random images of the whole gallery or the current album (and/or its subalbusm) you are within...

    EDIT: Strange thing is that we have a line in the documentation of getRandomImgesAlbum that speaks of an option to get an album folder, but the option itself is not there. Maybe something got lost on the way or was forgotten...
  • acrylian, I use PHP version 4.3.10/MySQL version 3.23.58
  • `GetRandomImagesAlbum()` does provide for the option to specify the album from which the images are obtained. If empty it uses `$_zp_current_album`. However, `printRandomImages()` does not have such a parameter, so it only uses the current album. It will be relatively easy to extend `printRandomImages()` to add this parameter and pass it throught to `getRandomImagesAlbum()`.
  • BertSimons:

    Does `getRandomImages()` work fopr you within Zenphoto? You can setup stopdesign to use it through the options.
  • nope sbillard.. as you can see at the moment at http://www.bertsimons.nl/zenphototest/ i'm using stopdesign with the same error result
  • trisweb Administrator
    The issue, I believe, is that 'SHOW' is a reserved word in MySQL (eg: SHOW ALL TABLES;) so it gets very confused if it shows up unquoted (in backticks).

    I'm all for changing the name of that column - we really shouldn't use reserved words even if we do make sure to quote them, it's just not good practice.

    For now, you can find some way to quote the column name, so it'd look something like `'zp_images'.'show'` (except - the single quotes should be backticks, but this forum won't show them since it uses that for code notation).
  • I suspect your version of MySQL is not allowing the `zp_images`.show perhaps. But then there should be other parts of zenphoto that get this error. You can try a change to the SQL circa line 2642 of template-functions.php. Change the ` prefix('images') . '.show, ' . prefix('albums') . '.show,` to ` prefix('images.show') . ', ' . prefix('albums.show') . ', '`
  • Tried that and it did not work. What does work at least with my version of MySQL, is
    putting peck marks arount the words show in the line. (Both instances.)
  • Or, even better still, delete both of them since they are not used.
  • The nightly will have the correction. There was still another place that needed to have peckmarks around "show".
  • sbillard, with the nightly build printRandomImages() now works in every theme and also in my own theme wp-sidebar. thanks team for solving this
  • Thanks for the report. Specially since all I could test was that the change did not break anything for me--the old code worked on my version of MySQL!
Sign In or Register to comment.