Showing Next-gen gallery inside the template file

I wanted to show the nggallery images in my web page using a php template tag in the theme template file. What i mean i wanted to use [nggallery id=6] in my template to show a particular gallery after matching a certain condition. I searched for a solution at their website but i finally got it at wordpress’s website here http://wordpress.org/support/topic/nextgen-gallery-in-template. To my surprise i could use the the_content filter to send the shortcode to parse and get the gallery. The example shows that you could use the custom field to fetch the gallery (which is still a little bit confusing to me), as the following:

$gallery = get_post_meta($post->ID, 'gid', true);
$gal = $gallery;
$gal = apply_filters('the_content', '[nggallery id='.$gal.']');
echo $gal;

But i just needed to do the following, as i could set $gal ID through my condition check.

$gal = apply_filters('the_content', '[nggallery id='.$gal.']');
echo $gal;

Leave a Reply

Your email address will not be published. Required fields are marked *