The gallery title in a custom NextGEN Gallery template

Tags: ,

When using custom album and gallery templates, NextGEN Gallery plugin doesn't provide any variables with the gallery name to the gallery template:


xdebug shows no title var in ngg custom tpl

My album and gallery templates are in "wp-content/ngg/modules/photocrati-nextgen_basic_album/templates/extended.php" and "wp-content/ngg/modules/photocrati-nextgen_basic_gallery/templates/thumbnails/index.php" respectively.

I've found only one datum which can lead to the current gallery title. It's gallery ID accessable by $displayed_gallery->container_ids from a gallery template. In my opinion, the best way of fetching the gallery title is to issue an SQL-query using one of the plugin's DAOData Access Objects are called DataMappers here, so we need a C_Gallery_Mapper:

$mapper = C_Gallery_Mapper::get_instance();
$gid = $displayed_gallery->container_ids[0];

$rows = $mapper->select()->where('gid = ' . $gid)->limit(1)->run_query();
$title = $rows[0]->title;

It's important to get data using the above SQL-query, because NextGEN Gallery uses exactly the same SQL-query further. Thus the plugin caches results of querying the database, the results of our SQL-query will be used by the plugin a little bit later (checked through MySQL general log).

08 February 2017

Comments (frozen for the time being)

No one has commented on this page yet.

Интернет реклама