How to add a button in a dynamic album ?


I would like to add a button in image.php that would only appear on dynamic pictures (a picture chosen from a dynamic album)

This button would be a link to the standard album where the picture has been published.

Example :
"my-picture" is published in "my-album". A tag is set and used in "this-dynamic album"
"my-picture" can be seen in "this-dynamic album"
The button that has to be displayed on "my-picture" page, accessed from the dynamic album should point to "my-album".

Sorry if this feature has already been discussed, my search function gave me no result.

Generally speaking, this could be a nice possibility for Zenphoto.

Thanks in advance.


  • acrylian Administrator, Developer
    edited February 2019

    All possible you have to use the object model. Knowledge about PHP object orientation required:

    On image.php use something like this if the image is directly within the dynamic album:
    if($_zp_current_album->isDynamic()) { //here do whatever you like to do. // $_zp_current_album->getLink() gets the URL to the dynamic album and not the real album the image is in and $_zp_current_album->getTitle() the title for display. }

    A basic example. The above might not work as expected for images within albums that are also results of the dynamic album (search).

    To get the real album the image is in use:
    $realalbum = $_zp_current_image->getAlbum();
    Then use the same methods as above for link and title. On images in real album context both albums would be the same.

    Basics of the object model here:
    Info on the classes on the functions documentation or within the files itself

  • ctdlg Member
    edited February 2019

    Thanks acrylian.

    This code:
    <?php if($_zp_current_album->isDynamic()) { $realalbum = $_zp_current_image->getAlbum(); ?> <a href="<?php $realalbum ?> " title="Origines" >Galerie parente </a> <?php } ?>
    returns the same dynamic album image link, not the original album link.

    The "if" function does work : no link on real album pictures pages.

    I had a look to your "Basics of the object model " page, but your code is OK, so, I do not understand what is wrong !

  • fretzl Administrator, Developer
    edited February 2019
    <?php if ( $_zp_current_album->isDynamic() )  {
     $realalbum = $_zp_current_image->getAlbum(); ?>
     <a href="<?php echo html_encode(getAlbumURL($realalbum)); ?>" title="Origines">Galerie parente</a>
    <?php } ?>
  • Thank you fretzl, it does work.
    I understand now a bit more Zenpage code !

  • acrylian Administrator, Developer

    Or $_zp_current_album->getLink() as I mentioned above.

  • ctdlg Member

    can we also add this button on search result image pages ?

    <?php if ( $_zp_current_album->isSearch() ) ... etc ...
    does not work !

  • acrylian Administrator, Developer
    edited May 2019

    $_zp_current_album->isSearch() does not work because it does not exist.

    To find out if an album is a dynamic album you have to use if($_zp_current_album->isDynamic()) { … } as noted above.

    The plain images result pages are not within an album context but in search context. To find ouf it you are on the search pages you can use if($_zp_gallery_page == 'search.php') { … } or also If(in_context(ZP_SEARCH)) { … }.

  • vincent3569 Member, Translator

    a suggestion: add a tag "album name" on each images.
    in image page from dynamic album, you can display all tags on this image and have a link to original album.

  • ctdlg Member

    Thank you for your help.
    I've used the suggestion of acrylian, but vincent3569 gives me a trick I can also use !

  • acrylian Administrator, Developer

    in image page from dynamic album, you can display all tags on this image and have a link to original album.

    If you like to do that this is possible much easier actually. You can get the real album object of an image using $realalbum = $_zp_current_image->getAlbum(). Then you can use $realalbum->getLink() for the link to the real album page.

    If you are using dynamic albums and also have your real albums reachable it is recommended to use the html_meta_tags plugin and enable the "canonical url". Then the image page will have an canonical entry to the real image location in the <head> to avoid duplicated content issues.

Sign In or Register to comment.