I've set up a template called archive-gallery.php, and I have pagination working, however, the query is ignoring my posts_per_page value and using the value that is in Settings > Reading called Blog Pages Show At Most. My gallery archive page is showing 8 posts per page, which I set, and I have 48 posts in the post type. This should give me 6 pages. Wordpress is only giving me 5 pages in the pagination using next_posts_link with $gallery_page_query->max_num_pagesincluded in the next posts link. When I go to the 6th page, which there is a link to in the pagination, I get a 404.

Here's my code:

Template Name: Gallery Archive
get_header(); ?>
  <div class="main" role="main">
    <div class="standard-section">
      <div class="gallery">
        <h1 class="big-centered-h1">
          Check out our latest work!
        <div class="gallery-images">
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $gallery_page_args = array(
              'post_type' => 'gallery',
              'posts_per_page' => 8,
              'paged' => $paged,
              'order' => 'DESC',
              'orderby' => 'date'
            $gallery_page_query = new WP_Query($gallery_page_args);
            if ($gallery_page_query->have_posts()) :
              while ($gallery_page_query->have_posts()) : $gallery_page_query->the_post();
                echo '<a class="img-gallery-wrapper" href="';
                echo get_permalink($post->ID);
                echo '">';
                echo '<img class="gallery-image" src="';
                $featured_image_url = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
                echo $featured_image_url;
                echo '">';
                echo '</a>';
          <div class="clearfix"></div>
        <div class="left-pagination">
          <?php previous_posts_link('&lt;&lt; Go back'); ?>
        <div class="right-pagination">
          <?php next_posts_link('See More &gt;&gt;', $gallery_page_query->max_num_pages); ?>
        <div class="clearfix"></div>
<?php get_footer(); ?>

The page in question is located at http://www.nickpassaro.com/clientsitedev/NJRI/gallery

If anyone could help me, I would really appreciate it.

  • Don't use the archive- prefix for page templates. This is confusing, not just for humans, but for Wordpress as well. If it is a page template, rather use the correct page- prefix Mar 5, 2015 at 5:21
  • Another point, do not use gallery as your post type name, it is a reseved name which will cause conflict with core naming conventions Mar 5, 2015 at 5:22
  • That worked! Thank you! Post your comment as an answer so I can give you credit lol! Mar 5, 2015 at 5:22
  • Great, glad it worked. Will post answer soon :-). Enjoy :-) Mar 5, 2015 at 5:24

1 Answer 1


Your problem is your naming convention. Look at the Template Hierarchy. The archive- prefix is reserved for date and custom post type archive pages. You are using this as prefix to a page template

This is not only confusing to humans, but to Wordpress as well. For page templates you should be using the page- prefix. Just a note, as from version 3.4 you don't need the page- prefix anymore for page templates :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.