Index shows first image of first album

Is it possible to call the first image of the first album directly into index.php? Currently I have to click through the link for an album, and then choose an image in order to see anything. That's a few more steps than I'd like. Ideally when the link to the zenphoto site is clicked the code would serve the first image up. I've already built the links to the other albums and the thumbnails for the current album into image.php so there's a way back. I'd rather not have to hard-code the link to the first image since this is for a client and it's quite possible that link would have to change regularly. Perhaps something like the "set context" call but for the first album of the set?

Comments

  • Is it possible to call the first image of the first album directly into index.php? Currently I have to click through the link for an album, and then choose an image in order to see anything. That's a few more steps than I'd like.

    I would also like to have this feature. Does anyone know how to get this to work?
  • try:

    `global $_zp_gallery;

    $alb = $_zp_gallery->getAlbums(0);

    $first = $alb[0];

    $firstAlbum = new Album($_zp_gallery, $first);

    $img = $firstAlbum->getImages(0);

    $first = $img[0];

    $firstImage = new Image($firstAlbum, $first);`
  • Sorry, I'm new with php. Where do I put the code?
  • You will have to put it in your index.php page where you want the link to the new image. However, this code only gets you the object for the new image. You will need to do more to show the link/thumbnail, whatever you wish.
  • Sorry but I must have misinterpreted Genial's request. I guess my question is different.

    What I would like to have is the normal index page that lists albums with thumbnails, but instead of showing the album view when a user clicks on a thumbnail from the index page, I would like it to link to the album's first image. Is there a way I could sidestep the album view page?
  • You can use the code above to get an object of the first image in an album. Then change the call on `getAlbumLinkURL()` to `$firstImage->getImageLink();`
  • I'm extremely new to this.
    Where on the album.php page should I paste the above code?
    Here's my album.php page:
    `<?php $startTime = array_sum(explode(" ",microtime())); if (!defined('WEBPATH')) die(); ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">





    <?php printGalleryTitle(); ?>

    /zen.css" type="text/css" />

    <?php printRSSHeaderLink('Gallery','Gallery RSS'); ?>

    <?php zenJavascript(); ?>











    <?php while (next_image()): ?>



    <?php endwhile; ?>

    <?php printAlbumDesc(true); ?>








    `
  • That really depends on where you want the thumbnail to appear on the page.

    A quick tour of the code above:
    the `gallerytitle` div is where the name and link back to the gallery page is done.

    the `images` is where your image thumbnails are generated.

    Note: this theme would not support subalbums. If you are really new to all this I suggest you take one of the existing themes--say the example theme (which is called testing in the 1.1.2 release) as a starting point.

    It is index.php which shows the first level albums. Second level albums (subalbums) are normally shown by the album.php page. However what you have above does not do them.
  • Thank you for the info about subalbums. I do not plan on using subalbums on my site so updating is not necessary.
    I have tried replacing the `images` div with your code on my album page, but I get a fatal error from the `$img = $album->getImages(0);` line.

    Where on the album.php should I add your code?

    Perhaps it would be easier for the album link on the index.php page to link straight to the first image of the album. Would this be possible?
  • You should read more carefully. If you don't plan to have subalbums, then there will NEVER be an album on the albums page, just the thumbnails for the images in the album. So, it is kind of pointless to put the code in the album.php file.
  • I have tried placing your code on my album.php page and then on my index.php page, and both return the following error:

    Fatal error: Call to a member function getImages()

    Is this a new function for ZenPhoto 1.1.2, or should I put the code somewhere else?
  • getImages is defined in class-album.php. It has been there forever. However, if you are not using the 1.1.2 release, please do. We cannot help you if you are not on current software.

    You do, of course, have to have a valid album object to use the function.
  • I have edited the code above to correctly use $firstAlbum. Please be sure that you take example code with a grain of salt. Obviously I have not implemented this function. I am trying to give you examples of how to do something. However, it is not final polished code and is created on the spur of the moment. You need to be able to understand what is attempted and make modifications as needed to make the code correct. If this is too much for you, then perhaps you should not be taking on this project.
  • I got it to work kind of!
    I upgraded to 1.1.2, put your new code on index.php and changed `getAlbumLinkURL()` to `$firstImage->getImageLink();`.
    It does work, except now all of the thumbnails on the index page point to the first photo of the first album. I played around a little and noticed that if I change the number from 0 to 1 in the `$first = $alb[0];` line, the thumbnails would then link to the first image of the second album.

    Is there a way for each of the albums on index.php to have their own link be first image of their album?

    Here's my index.php file:

    `<?php if (!defined('WEBPATH')) die(); ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">





    <?php printGalleryTitle(); ?>

    /zen.css" type="text/css" />

    <?php printRSSHeaderLink('Gallery','TedPhoto'); ?>

    <?php zenJavascript(); ?>







    <?php echo getGalleryTitle(); ?>








    <?php while (next_album()): ?>

    <?php global $_zp_gallery;<br />
    $alb = $_zp_gallery->getAlbums();

    $first = $alb[1];

    $firstAlbum = new Album($_zp_gallery, $first);

    $img = $firstAlbum->getImages(0);

    $first = $img[0];

    $firstImage = new Image($firstAlbum, $first);

    ?>



    <?php endwhile; ?>



    <?php printAdminToolbox(); ?>



    `
  • Anyone willing to help?
  • Sorry for raising a dead topic but I'm trying to acomplish the same thing. But the index.php is different now and I don't know how to solve my problem.

    I tried to change
    `"`
    to
    `
    "`
    But I guess you need to define what album you'r trying to enter.
  • I still haven't solved my problem. I read the "Skipping (sub) album view" threat but that didn't help me.
Sign In or Register to comment.