Nextgen Gallery is pretty famous gallery plugin used in WordPress. It provides shortcode to insert gallery in posts,pages, sidebars etc. In this post, we are going to use nextgen’s built in functions to show these galleries, albums in WordPress template files. Ideally we show the Nextgen gallery on a page or post using the shortcode [nggallery id=x] , where x is the gallery id which you want to show. One way is to execute this short code in any template file using this do_shortcode method, explained in the post. But we are going to use the alternate method which is the right way to do it.
How to show the Nextgen Gallery
<?php $ngg = new NextGEN_Shortcodes; echo $ngg->show_gallery( array("id"=>$gallery_id,"images"=>num_img,"template"=>"mygallery") ); ?> |
$gallery_id = You can assign gallery id which you want to show.
num_img = integer value of number of images you want to show
mygallery = template we are using to display the images.
By default nextgen provides gallery templates like compact, popular, extend etc. But you can create your own template as suggested in this post How to create Nextgen gallery custom template.
That was for the images being shown from a particular album. Now we are going to see how can you show albums into your template files, which are created using Nextgen gallery.The shortcode for showing album is – [ album id=x template=extend] , where x is the album id.
How to show the Nextgen Albums
<?php $ngg = new NextGEN_Shortcodes; echo $ngg->show_album( array("id"=>$album_id, "template"=>"extend") ); ?> |
Here $album_id is the album id generated by nextgen in your wordpress admin.
Show single picture thumbnail
<?php $ngg = new NextGEN_Shortcodes; echo $ngg->show_thumbs( array("id"=>$picture_id, "template"=>"") ); ?> |
Here $picture_id is the id of the image of which you want to show the thumbnail.
Show single picture
<?php $ngg = new NextGEN_Shortcodes; echo $ngg->show_singlepic( array("id"=>$picture_id,"w" =>'',"h"=>"","mode"=>"","float"=>"","link"=>"","template"=>"") ); ?> |
Where,
$picture_id = id of the picture to be shown
w = width of the image
h= height of the image
mode = web20 or watermark , where web20 adds reflection and watermark adds a watermark defined in the settings
float = CSS left|right float values
template = specify a template
Hope the above information will help you create some awesome web designs. Do let me know your comments & suggestions.
Stay Digified!!
Sachin Khosla