Few days ago a friend of mine, a good photographer, asked me to help her building her website. I told her the fast and dirty way to do that was to buy a theme on theme-forest.com and mount it on a wordpress on my hosting. We looked together for a good looking theme and we ended up with Keres .

After buying it, we discovered it was missing one of the most natural feature you would like to find on a galleries website:
the galleries index
or a page where there are all your galleries with a skin picture and the gallery name.


Keres Theme

Keres Theme

I decided to help her and after a lot of headaches understanding the theme structure  and 4 hours I ended up writing some code.

This code is nothing more than a template, which will display your galleries in a simple grid of 4 columns. It will only works for galleries with masonry template, because I didn’t have the time to make it universal.
If you use a different theme for galleries edit line 207 with your template name. It will not work if you use different themes for each gallery (cpt. Obvious).

Create Categories for Galleries:

Use a plugin to enable categories on pages. Like “Ninja Pages, Categories, and Tags“.

Set categories as children of the main category ‘Gallery’, like in this picture:


Nested Categories

Nested Categories

List all the galleries (display just one pic each):

Create a file called “template-archive-gallery-4.php” (just a name) in the folder of your theme.

Copy inside the following code:


Create a page called Galleries (check the permalink, make it nice), and assign the template we’ve just created.


List galleries of one category

To list galleries of one category we have to add a shortcode:

[lenotta_catlist lenotta_cat_name=”fashion”]

Then we create a page with this shortcode for each gallery. Be sure the name check the slug.

Add this code to functions.php to create the shortcode:



It’s far away to be super efficient, but it works.

And here is the result:


Galleries Index

Galleries Index

I also edited a line of css because (don’t ask me why) it was not showing correctly:

On file  css/screen.css line 1256 the orginal is  : “margin-right: 15px;”  and the modified is “margin-right: 10px;”.

Hope the author don’t mind if I publish this, and feel free to use my lines of code however you want.

Happy coding!



Post a comment
  1. Derek #
    August 7, 2015

    I can do this without code just through the theme options. I had to use a similar hack to yours at first,then through raw gumption I found a way around it, it’s a bit long winded but I think its the way the theme works or was just a non code hack that my perseverance discovered.

    With practice you can add anew gallery to the page in 5 mins. If anyone needs this let meknow I will write a detailed account on hoe I went about it.

    • December 12, 2015

      When the article was written it wasn’t possible to do it. If things have changed, could you share it with me so I can point the readers in the right direction? Thank you very much.

  2. Nicholas #
    January 23, 2014

    Hi edu!

    do you know how to add a video background but NOT from youtube or vimeo? i mean, a video from host-server.

  3. KEP #
    December 16, 2013

    Hi Edoardo!

    Thank you for posting this hack. I, too, am using the theme and am far from being a developer, to be sure–but I do have WP experience and some good friends who are both very conversant in WP and they write code.

    They are all stumped by this template. And you are correct, you can’t mix the gallery types among pages, and, for some reason, the image titles and captions have stopped showing. I’ve figured out the extent of everything you mentioned, but this is now at issue. Well, that, and I changed all of the photos have been scaled back to 1024 px as recommended by the author, and no change. What is the key, here?

  4. Baba #
    December 11, 2013

    I think I found the solution for the line 191 error.
    Replace in template-archive-gallery-4.php:

    $pid = $wpdb->get_var( $wpdb->prepare(“SELECT post_id FROM $wpdb->postmeta WHERE meta_value = ‘$key->ID’ AND meta_key = ‘page_gallery_id’ ORDER BY post_id DESC”) );

    with this:

    $pid = $wpdb->get_var( $wpdb->prepare(“SELECT post_id FROM $wpdb->postmeta WHERE meta_value = ‘$key->ID’ AND meta_key = ‘page_gallery_id’ ORDER BY post_id DESC”, $id, $name) );

    And the error is solved!

    Now I still need help myself with pulling in all the galleries when it should just pull in two. Can you help me?

    • December 12, 2013

      I’m sending you an email. If you would suggest the changes you made which differ from the article, I could publish them, quoting you for the help of course!

    • December 12, 2013

      I’ve just edited the code with your solution, thank you so much!

  5. Ryan #
    November 15, 2013

    Hey, thank you for this hack. Im having problems with it however. Im receiving this Warning on the page.

    Warning: Missing argument 2 for wpdb::prepare(), called in /home/kayradph/public_html/wp-content/themes/keres/template-archive-gallery-4.php on line 191 and defined in /home/kayradph/public_html/wp-includes/wp-db.php on line 992

    • November 20, 2013

      Can you send us what’s on line 191 of template-archive-gallery-4.php? Thank you.

      • Baba #
        December 11, 2013

        Hi Edoardo!

        I have the same problem!
        Here is the content of line line 191 of template-archive-gallery-4.php:

        $pid = $wpdb->get_var( $wpdb->prepare(“SELECT post_id FROM $wpdb->postmeta WHERE meta_value = ‘$key->ID’ AND meta_key = ‘page_gallery_id’ ORDER BY post_id DESC”) );

        I also seem to have the same initial problem as caleb, it pulls in all the galleries when it should just pull in two.
        I have read that you had a solution for this which you could not post here, could you mail it maybe to me?
        Already many thanks! You have done a great job!

  6. August 1, 2013

    Hi Edoardo,

    We got it to work! Thank you for your help. You’re were 10 time more helpful than the author. I really appreciate it.

    As an FYI, we had to remove the following DIV below from the original template-gallery-4.php get it to work:

    <div class="one_fourth gallery4″>

    <img src="” alt=”” class=”one_fourth_img”/>

    <a title=”” class=”fancy-gallery” data-fancybox-group=”fancybox-thumb” href=”post->ID );?>”>

  7. July 30, 2013

    Hi Edoardo,

    Thanks for updating your post with the additional information. We’re closer, but still having issues. The gallery index page now shows the correct galleries that it should pull in (Honduras and Turks & Caicos), but still pulls in every one of the remaining galleries.

    I sent you and email of screenshots to show how we’ve set everything up. Can please take a look to see what we are missing?

    Thanks again for all the help.


  8. July 25, 2013

    Hi Edoardo,

    Thanks so much for posting your hack. I too have the Keres theme and have say I totally agree with you that this was a complete miss to leave this feature out. I have contacted the author tons of times and he is never responsive and thus I am stuck trying to create a gallery index on my one.

    My friend is a web developer and has been helping me out, but we can’t seem to get the pages to load correctly.

    For example, http://www.calebwolper.com/galleries/urban/ pulls in all the galleries when it should just pull in two.

    Can you make recommendation on how to fix this?

    Your help is VERY appreciated.

    Thanks from San Francisco,


    • admin #
      July 26, 2013

      Hi Caleb!
      I’m glad the post was helpful to you. The structure of this theme is a little bit complicated ( the kind of complication that comes out from a not clear base project or an evolution of an older one I think).

      I don’t have really clear what is your problem. I’ve applied the modified theme to martinagiachi.com do if you find that it matches your needs then I can send it to you.

      A little bit of knowledge about the theme (made with reverse engineering):

      Actually each gallery is indeed a custom post. For each gallery, as you’ve probably seen, you need to create a page. Then you assign the gallery to a page with the custom field (on the page) ‘Content Gallery’.

      I’ve used categories to distinguish different type of galleries (assigning a category to page with “Ninja Pages, Categories, and Tags” plugin) and “List category posts” plugin to list them.

      Let me know if you need other infos.
      Good luck.

      • July 26, 2013

        Hi Edoardo,

        Thanks for the quick reply. You’re super helpful. I really appreciate it.

        Yes I would be very happy just replicating the modified theme you used for martinagiachi.com.

        If you can send that to it would be great. I believe my friend can get everything sorted out from there.

        Thanks again!


        • admin #
          July 26, 2013

          Hi Caleb,
          just sent you the modified theme by mail. Obviously I can’t publish it, because of copyright… If you need more help or find a solution contact us.
          Keep us update!

          • Randy #
            July 26, 2013


            My name is Randy, I am helping out Caleb with his site.
            thanks for helping us out.

            I believe I understand what you have said above:
            I’ve used categories to distinguish different type of galleries (assigning a category to page with “Ninja Pages, Categories, and Tags” plugin) and “List category posts” plugin to list them.

            My question is how did you assign categories to the individual galleries in order to separate them? They are all listed as uncategorized and there is no place to edit them.

            If these can be labeled with a category, and then call these categories within one of the gallery landing pages with the use of one of the plugins above, seems to be how you accomplished your separation so that all your galleries do not display.

            Thanks, Randy

          • July 27, 2013

            Hi Randy,
            actually I do not assign categories to galleries, but to the page linked with the gallery. That’s why I needed the “Ninja Pages, Categories, and Tags” plugin, because usually pages haven’t categories.
            Hope it helps.

          • July 28, 2013

            Hi Edoardo,

            I think we’re closer, but still not there. We created a bunch of categories for the site, but can’t seem to get the landing page to populate correctly.

            Here is the landing page I have been testing: http://www.calebwolper.com/under-water/

            If it worked correctly it should pull two galleries into it: Honduras & Turks & Caicos. Instead, it pulls in a bunch of the other galleries randomly.
            My guess is that this has to do with how to properly categorize each page. I’ve tried many different combinations, but nothing seems to work.

            Here are the pages it should be pulling in: http://www.calebwolper.com/turks-caicos/ http://www.calebwolper.com/honduras/

            For example, I created the Under Water,Turks & Caicos and the Honduras categories and played with checking all as Under Water or both Under Water & Turks & Cacios, etc. and nothing seems to work.

            Can you send me screen shots of how you categorize the landing page, and pages that you want pulled in?

            This would be super helpful.

            Thank you so much!


          • July 28, 2013

            Hi Caleb,
            just updated the post, check if it’s more clear now. I think I’ve made some wrong assumption because of bad memory, sorry for that.
            Let me know.

Leave a Reply

Basic HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS

By continuing to use the site, or scrolling, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.