Nextgen Gallery is a perfect gallery plugin for wordpress. I use it most with my wordpress theme projects. Here i will show you how to display nextgen gallery using php code in your page templates.

Nextgen gallery has a shortcode to add any gallery to your post. But if you want to display the gallery in your header, slider or sidebar you need to customize your theme files a bit. To achive this we will use Custom Field gallery_id.

First you need to enter gallery_id‘s in the custom field and save.

Then open single.php for posts, page.php for pages and add this code where you want your gallery to appear:

  $gallery_id = get_post_meta( $post->ID, 'gallery_id', true); // Get gallery id from custom field data
  if( isset($gallery_id) ){ 
    echo "<div class="post-gallery">";
    echo nggShowGallery( $gallery_id ); // Display the gallery
    echo "</div>";

Save and upload the file to your dedicated server.

This will show a gallery if one is set using custom fields.

If you want a better user experience you can add a metabox for selecting gallery ids.

Deal Notice: We are using A2 hosting for all of our websites, and we are really happy with their service. So we wanted to share you this discount link for you to try it out. If you get a hosting using this link, you will also help us build better content for you: SSD Hosting - 300% Faster Than Standard Hard Drives