Title: Template file for galleries
Last modified: August 22, 2016

---

# Template file for galleries

 *  Resolved [rhf](https://wordpress.org/support/users/rhf/)
 * (@rhf)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/template-file-for-galleries/)
 * Hi. I’ve just started using your fine product and am very impressed.
 * I am adding an album with multiple galleries to a page with a simple page template.
   When the user selects one of the galleries, the gallery opens using the same 
   page template. I would like to add a link so the user can return to the original
   album page, but I don’t what to search for so that I can add conditional logic
   to the template to display the link.
    Any ideas? Thanks.
 * [https://wordpress.org/plugins/nextgen-gallery/](https://wordpress.org/plugins/nextgen-gallery/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [tizz](https://wordpress.org/support/users/tizz/)
 * (@tizz)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/template-file-for-galleries/#post-5378428)
 * [@rhf](https://wordpress.org/support/users/rhf/), [here](http://codex.wordpress.org/Conditional_Tags)
   you can find documentation about conditional tags, and [here](http://www.nextgen-gallery.com/templates/)
   some hints to create page templates (but if you link the gallery to a page and
   you have a particular template for that page, you don’t need conditional tags).
 *  Thread Starter [rhf](https://wordpress.org/support/users/rhf/)
 * (@rhf)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/template-file-for-galleries/#post-5378454)
 * Thanks, tizz.
    I did a poor job of describing my problem. I have an album on 
   a page that consists of several galleries. The page uses a special temple which
   does what I want. When one of the galleries is selected, it opens on the same
   page with the same template as the album. This is not too bad, however a link
   on the gallery page back to the album page would be very desirable. I thought
   I could do this with some simple logic, but both the album page and the gallery
   page have the same title and the same permalink, so I don’t know what to test
   for.
 *  [tizz](https://wordpress.org/support/users/tizz/)
 * (@tizz)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/template-file-for-galleries/#post-5378457)
 * [@rhf](https://wordpress.org/support/users/rhf/), the easy and safe way is to
   create a template for galleries pages, I’ve tried it just for you and it works
   well.
    _This is if you have the gallery linked to a page._ Add in that template,
   just before the content, a thing like this:
 *     ```
       <div id="backtoalbum">
       <a id="return" href="http://mysite.com/albumpage/"><?php print "<< Back to Album" ?></a>
       </div>
       ```
   
 * The div and the ids are for assign a style with CSS if you want to, and of course
   you can change any terms as you want. Remember to assign the template to that
   page.
    _If you don’t have the gallery linked to a page_, follow the instructions
   at the second link in my previous post. Put in that template that same code, 
   after `<?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?><?
   php if (!empty ($gallery)) : ?>` Then in Gallery settings > basic thumbnails 
   > template, paste the name of your template and save.
 *  Thread Starter [rhf](https://wordpress.org/support/users/rhf/)
 * (@rhf)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/template-file-for-galleries/#post-5378460)
 * Tizz,
    Thank you very much for your suggestions. I had sort of given up on an
   easy solution, and your ideas encouraged me to try again. It turns out that $
   _SERVER[‘REQUEST_URI’] was what I needed to do the simple logic in my existing
   template file. That is, I set `$pos = strpos($_SERVER['REQUEST_URI'], 'nggallery');`
   If on the Album page, $pos is false; if one of the galleries is displayed, it
   is not false. I then use a simple conditional to display the link when a gallery
   is showing. I expect that your solution is much better than mine, but this simple
   logic is sufficient for my application. Again, I really appreciate your help.
   Thanks.
 *  [tizz](https://wordpress.org/support/users/tizz/)
 * (@tizz)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/template-file-for-galleries/#post-5378468)
 * [@rhf](https://wordpress.org/support/users/rhf/), I’m glad if you have find the
   right solution for you.
    Some more explanation – not for you, but for those who
   would be interested in: Last night I forgot to say that after “_If you don’t 
   have the gallery linked to a page, follow the instructions at the second link
   in my previous post_” I had to add “until the fourth point”, because this is 
   the case of the gallery not linked to a page, so isn’t possible use the shortcode.
   Also, I’m not sure that putting the name of the template in the settings will
   work for everyone. At last, when a gallery is linked to a page but you prefer
   the use of IGW button to display it, you can create your template as you would
   for your child theme, put it in child theme’s folder and choosing it from the
   dropdown menu.
 *  Plugin Contributor [photocrati](https://wordpress.org/support/users/photocrati/)
 * (@photocrati)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/template-file-for-galleries/#post-5378474)
 * Thanks, [@tizz](https://wordpress.org/support/users/tizz/)!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Template file for galleries’ is closed to new replies.

 * ![](https://ps.w.org/nextgen-gallery/assets/icon-256x256.png?rev=2083961)
 * [Photo Gallery, Sliders, Proofing and Themes - NextGEN Gallery](https://wordpress.org/plugins/nextgen-gallery/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/nextgen-gallery/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/nextgen-gallery/)
 * [Active Topics](https://wordpress.org/support/plugin/nextgen-gallery/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/nextgen-gallery/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/nextgen-gallery/reviews/)

## Tags

 * [album](https://wordpress.org/support/topic-tag/album/)
 * [gallery](https://wordpress.org/support/topic-tag/gallery/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * 6 replies
 * 3 participants
 * Last reply from: [photocrati](https://wordpress.org/support/users/photocrati/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/template-file-for-galleries/#post-5378474)
 * Status: resolved