Search code examples
javascriptphpwordpressnextgen-gallery

Recent galleries on NextGen Gallery plugin Wordpress


I am using Nextgen gallery plugin on wordpress, version 3.55. I would like to get the more recent galleries uploaded and then show them in the homepage. How can I retrieve all galleries ID and the show the latests three? Maybe using a php array? I need a step by step guide just to learn how the plugin works on retrieving galleries

Maybe I can use the "global $wpdb" variable to access the database and then work on the table wpxxxxx_ngg_gallery to get an array with all the galleries ID just to pick the latest 3?

I found a solution but now I need to know how to use a variable used in the plugin NExtGen Gallery. In particular, I am trying to get the breadcrumb of the gallery. I ve noticed breacrumbs.php exists under nextgen-gallery\templates\Albums but I dunno how to get and use the variable $breadcrumbs on my php file.

Any suggestion?


Solution

  • I think I solved, even if i don't know how. Here's my code, hope could be helpful for someone.

    function last_3_galleries() { 
    
    global $wpdb;
    // perform a query on db to get all gallery slug ordered by date 
    $all_galleries = $wpdb->get_col( "SELECT slug FROM
    wpPREFIX_ngg_gallery ORDER BY date DESC" );
    
    // declare array for galleries and select last 3 inserted slug
    $last_galleries=array_slice($all_galleries, -3, 3, true);
    
    // perform a for loop to display url of galleries
    for ($i=0; $i <= 2; $i++) {
    echo "<a href=' https://www.domain.it/NAMEOFALBUM/FIXED_SLUG_IN_NGG/WHATEVER/".current($last_galleries) . "'>".current($last_galleries)."</a><br>";
     next($last_galleries);
        }
    
    // register shortcode
    add_shortcode('CallShortcode', 'last_3_galleries');
    

    Please note that this trick is working but:

    • you must have a main NAMEOFALBUM set (I use it to display the list of all album)
    • you have to set the FIXED_SLUG in NextGen Gallery Plugin (under option->miscellaneuos)
    • the WHATEVER world in the link is really whatever world, I think wordpress (or maybe NextGen Gallery) is capable to retrieve the right gallery using only the slug of it.

    I don't know why, but once you printed the link, even if the name of the album is wrong, it shows the right gallery (be aware that the link in the address bar is probably wrong)