Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm having a tough time getting this to work. It's not the first time I run into problems with pagination, or I would say with WPs URL system.

Basically I have this URL:

http://example.com/location/dc 

and loads up the taxonomy-location.php template.

Now, I'm adding the pagination feature to the theme. So I have this URL:

http://example.com/location/dc/page/2

and it won't load the taxonomy-location.php template, it actually loads the 404 template.

This is what the debug bar shows:

http://cl.ly/1u0F470k062o1Q121u15

It seems like it's getting the right values, WP is just not loading up the correct template.


EDIT (Moved over from the comment links)

functions.php

/* LOCATION */
add_rewrite_rule( 'location/([^/]+)/page/([0-9]{1,})/?$', 'index.php?location=$matches[1]&paged=$matches[2]', 'top' );

taxonomy-location.php

  <?php 
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  query_posts($query_string.'&posts_per_page=2&paged='.$paged);
  ?>

  <h2>"<?= ucwords(get_query_var('location')); ?>" Venues</h2>

  <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

  <article>
    <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('venue_thumb'); ?></a>
  </article>

  <?php endwhile; ?>

    <?php wp_pagenavi(); ?>

  <?php else : ?>

    <article>
      <h1>No posts found</h1>
    </article>

<?php endif; ?>
share|improve this question
    
Lots of things can mess this up. Do you have any plugins installed? Have you used "query_posts" in your development? –  tollmanz Nov 28 '11 at 3:54
    
I do have a couple of plugins installed. I have, but only in the custom templates. It doesn't make sense that using query_posts would affect it since the template is not being loaded at all. –  criticerz Nov 28 '11 at 4:25
1  
"query_posts", if used incorrectly, can have significant effects on the WordPress environment. In particular, it can change the main WP query which affects things like pagination. Can you do a pastebin of your template and your functions.php file? –  tollmanz Nov 28 '11 at 4:43
    
@criticerz All your additional info is spread around comments. Please don't do that. Always update/edit your question and add the info to it. Then notify people in comments about your update. –  kaiser Mar 13 '13 at 14:50

2 Answers 2

Try adding 'paged' => get_query_var( 'page' ) to your query.

EDIT : For pagination to work properly the posts per page should be greater than 'Blog pages show at most' under Settings-> Reading section of the WordPress Admin. So there are two ways you can make this work out.

  1. You can set 'Blog pages show at most' to 1. This would show 1 post in all the blog pages unless you specify post_per_pages specifically for each query.
  2. The other option you have would be to use the pre_get_posts filter.

Example of pre_get_post filter to limit the no. of posts on a location taxonomy archive page to 2 posts per page.

function location_posts( $query ) {
    if( is_tax( 'location' ) ) {
        $query->set('posts_per_page', '2');
    }
    return $query;
}
add_filter('pre_get_posts', 'location_posts');
share|improve this answer
    
I am using that on my query already: cl.ly/3W2p220Z2t2w2e1e2L3A –  criticerz Nov 28 '11 at 4:26
    
You are using get_query_var('paged'). Try using get_query_var('page'). Notice 'page' instead of 'paged'. –  Joshua Abenazer Nov 28 '11 at 4:29
    
Tried that and nothing. I'm pretty sure it's supposed to be "paged". Anyways, the issue I'm having doesn't even get to the query_posts. My problem is that once I add the "page/2" to the URL, it won't load the taxonomy-location.php template. –  criticerz Nov 28 '11 at 4:34
    
Can you tell me what 'Blog pages show at most' is set to under Settings-> Reading in the Dashboard? –  Joshua Abenazer Nov 28 '11 at 4:44
    
Sure here you go: cl.ly/3h3T38413B0G2r0d0O2d –  criticerz Nov 28 '11 at 14:03
register_post_type( 'lifestyle',
                array( 
                'label' => __('Lifestyle', 'tmi'), 
                'public' => true, 
                'show_ui' => true,
                'show_in_nav_menus' => true,
                'rewrite' => true,
                'hierarchical' => true,
                'menu_position' => 5,
                'exclude_from_search' =>false,
                'supports' => array(
                                     'title',
                                     'editor',
                                     'thumbnail',
                                     'excerpt',
                                     'revisions')
                    ) 
                );

    register_taxonomy('lifestylecat', __('lifestyle', 'tmi'),array('hierarchical' => true, 'label' =>  __('Categories', 'tmi'), 'singular_name' => __('Category', 'tmi'))
    );
share|improve this answer
    
Almost there. Please add an explanation to make this a legitimate answer. –  Brian Fegter Oct 8 '12 at 13:49
    
How does this relate to the answer? Please edit your question or delete it. –  kaiser Mar 13 '13 at 14:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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