Using nextGen Gallery.. how can I call a list of all Gallery Names?

All your Galleries are stored a table called wp_ngg_gallery in your wordpress database. (For the sake of completeness: nextGen Gallery creates 2 more tables for albums and pictures, respectively)

$gallery_ids = $wpdb->get_results(
    "SELECT gid FROM ".$wpdb->prefix."ngg_gallery ORDER BY gid ASC", ARRAY_A);

fetches the IDs of all galleries into an array, ordered by ID from 1 to end. Now for excluding the two that are slideshows (the example will assume their IDs are 4 and 25):

$gallery_ids = $wpdb->get_results(
    "SELECT gid
     FROM ".$wpdb->prefix."ngg_gallery
     WHERE gid NOT IN (4, 25)
     ORDER BY gid ASC", ARRAY_A);

What good are the IDs without the galleries’ titles? Also, wouldn’t it be easier to exclude by title? So this

$galleries = $wpdb->get_results(
    "SELECT gid, title
     FROM ".$wpdb->prefix."ngg_gallery
     WHERE title NOT IN (slideshow_1, slideshow_2)
     ORDER BY title ASC", ARRAY_A);

would give you an array of all non-slideshow galleries ordered alphabetically by gallery title. You could also select with a wildcard * instead of gid, title, then you’d get all columns from the gallery table, which are gid, name, slug, path, title, galdesc, pageid, previewpic, author.

The resulting array is obviously meaningless unless you do something with it, such as iterating over it and creating a list of links.

The structure of the resulting array is:

Array
(
    [0] => Array
        (
            ['gid'] => 4
            ['title'] => 'playing_football'
        )
    [1] => Array
        (
            ['gid'] => 8
            ['title'] => 'vacation_pics'
        )
)

You get the idea.

EDIT: Creating a navigation from the above database query

Assuming that you already have created pages for all galleries from within the NextGen Gallery > Manage Gallery dialog, the following will create a simple navigation from it. The pageid and title columns must have been selected from the databse.

echo '<ul>';

foreach ( $galleries as $gallery ) {
    echo '<li><a href="' .
         get_bloginfo( 'url' ) .
         '/?p=' .
         $gallery['pageid'] .
         '">' .
         $gallery['title'] .
         '</a></li>';
}

echo '</ul>';

Reading, in case you care:

Leave a Comment