• Hi Photocrati

    How do I get the currently displayed gallery id in NGG v2.x, form inside a display template? For example sake, I am using “NextGEN Basic Thumbnails”, with no extra display template selected. This means NGG uses the /nextgen-gallery/products/photocrati_nextgen/modules/nextgen_basic_gallery/templates/thumbnails/index.php template.

    $displayed_gallery_id has an integer, but it’s definitely not the gid from the wp_ngg_gallery table.
    $displayed_gallery->ID, and $displayed_gallery->id() return the same integer as above.

    I tried to search through the $displayed_gallery object, and it appears the correct galleryid is in there, but the correct way to dig it out eludes me.

    Any help would be appreciated, I know you have your hands full with more pressing requests at the moment.

    http://wordpress.org/plugins/nextgen-gallery/

Viewing 8 replies - 1 through 8 (of 8 total)
  • I too am looking for a way to grab the current gallery ID, but for the life of me can’t figure it out either. Been poking through all the modules and template files, and haven’t found anything useful.

    Please post back if you end up finding a solution.

    Hi there,

    Thanks for the inquiry.

    In NextGEN Gallery 2.0, there’s the concept of a “displayed gallery”. A displayed gallery can be thought of as a a query for a list of images, regardless of what galleries the images come from. A displayed gallery also associates a particular display type and display settings for this list of images.

    Here’s an example of how you would construct a displayed gallery with the intention of fetching images from gallery #1:

    $factory = $this->get_registry()->get_utility('I_Component_Factory');
    $displayed_gallery = $factory->create('displayed_gallery');
    $displayed_gallery->container_ids = array(1);
    $displayed_gallery->source = 'galleries';
    $images = $displayed_gallery->get_included_entities();

    The $images array contains image objects, each of which have a “galleryid” property. You can simply use this to reference the id of the gallery associated with each image.

    Depending on what you’re trying to accomplish, it might make sense to reference $displayed_gallery->container_ids or iterating through the $images array and accessing the galleryid property: $image->galleryid

    I hope that’s helpful. If not, please post back and I’ll try to explain further.

    Thanks!
    Mike

    Thread Starter shauno

    (@shauno)

    Hi Mike

    Thanks for the response.
    So it seems $displayed_gallery->container_ids[0] will have the gallery id as I require it, but only for the ‘new’ display templates.

    If I select “NextGEN Basic Thumbnails”, with the “gallery-caption.php” template selected, NGG will load /nextgen-gallery/products/photocrati_nextgen/modules/ngglegacy/view/gallery-caption.php. Obviously that is legacy, so it doesn’t seem to follow the same architecture. The $gallery->id used to be publically accessible and have the value I require pre v2, but that’s not true anymore.

    Is there a nice, generic way I can get the gallery id in all display templates?

    The reason I ask, is I author a few NGG plugins that link data to galleries, and my APIs take the gallery id to do anything. Obviously my users aren’t always developers, so I need to be able to give them a copy/paste way of inserting my ‘tags’ into their display templates.

    Hi Shauno,

    The “Displayed Gallery” object allows to query for a list of images from multiple galleries, whereas the legacy templates in 1.9.x were designed to work with a single gallery, and therefore they don’t fit well with the design of NextGEN Gallery 2.0 and hence have been deprecated. We’ve done our best to keep this mechanism available for backwards compatibility, but to future-proof your code I’d suggest you review how to create a display type. I’ll post back with a link to a tutorial, but feel free to study our source code as well.

    In the mean time, the $gallery variable in legacy templates will have the following properties:

    • ID
    • name
    • title
    • pageid
    • anchor
    • displayed_gallery (instance of C_Displayed Gallery)
    • ID
    • source
    • container_ids
    • excluded_container_ids
    • entity_ids
    • exclusions
    • display_type
    • display_settings (array)
    • transient_id
    • slug
    • order_by
    • order_direction
    • returns
    • maximum_entity_count

    If you’re wanting to know what galleries are being displayed in the template, then perhaps you’d like to reference $gallery->displayed_gallery->container_ids

    Cheers,
    Mike

    Thread Starter shauno

    (@shauno)

    $gallery-ID again isn’t the gid you would expect, and while $gallery->displayed_gallery does appear to be an instance of C_Displayed_Gallery, the container_ids property is a blank array.

    So the answer to

    Is there a nice, generic way I can get the gallery id in all display templates?

    appears to be “no”.

    I guess I will have to study your source and see if I can write my own so I can give my users who barely understand the difference between PHP and HTML an easy way to get the data they need.

    I realise dealing with legacy of this size is difficult, so thanks for the info you have been able to give so far.

    What, if any filters/hooks exist to hook the displayed gallery, outside of templates, short of using a global?

    @lagdonkey, NextGEN Gallery uses Pope for extensibility:
    https://bitbucket.org/photocrati/pope-framework

    We opt for using Pope’s adapters rather than hooks/filters so that in the future, if we’d like, we could take NextGEN Gallery to another platform, such as Joomla. Note, porting to other platforms is not on the roadmap, and not likely to be added any time soon.

    Thanks,
    Mike

    Hi guys,

    Sorry if I might be intruding on the subject, but I figure my question is closely related.

    I’m trying to check the ID of an album being loaded, from within the compact.php template. Can you possibly point me in the right direction on how to achieve that?

    I’ve googled forever and tried everything I can think of to no avail..

    Thanks in advance, best/Dag

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Get gallery id in template’ is closed to new replies.