Taxonomy Pagination
-
Has anybody ever figured this out yet? You Google it and there are a billion blogs and forums looking for how but no answers or even failed attempts to answer.
-
Might need to expand on what’s not working for you.
Using the TwentyTen theme, with default Permalins, and with Settings->Writing set to 1 post page, when I visit a taxonomy archive (archive.php used from Twenty Ten) pagination works just fine.
It’s hard to narrow it down any more than it just doesn’t work.
Right now my taxonomy template file queries the posts fine using this
<?php $posts = query_posts($query_string . '&orderby=title&order=asc&posts_per_page=5'); if (have_posts()) : while (have_posts()) : the_post(); ?> <a>" rel="bookmark"> <?php the_title(); ?> </a> <?php the_excerpt(); ?> <?php endwhile; ?> <?php endif; ?>
And then I just copy and pasted the pagination code from the TwentyTen loop.php file
<?php if ( $wp_query->max_num_pages > 1 ) : ?> <?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyten' ) ); ?> <?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyten' ) ); ?> <?php endif; ?>
But if I have two pages and click the older posts link, it gives me a 404, if I have 4 pages it will take me back to one older page, but for the 3rd and 4th pages it gives me 404s.
All of the individual posts are fine, all the links that show up work fine, if I remove the limited posts per page it will display every single post listed under that taxonomy term and link to the posts fine.
Example of proper pagination (using the paged query var):
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('cat=3&posts_per_page='.get_option('posts_per_page').'&paged=' . $paged); ?>
Thanks MichaelH, but that isn’t even displaying the links now.
Then paste your complete template in a pastebin (e.g. wordpress.pastebin.com), report the link back here and maybe someone can spot the problem.
This is with what you suggested
https://wordpress.pastebin.com/qUy09Ac0
And this is what I was trying and works only if I have four pages and only links back to one previous page
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts($query_string .'&posts_per_page=5&paged=' . $paged); if (have_posts()) : while (have_posts()) : the_post(); the_title(); the_excerpt(); endwhile; ?> <div class="navigation"> <div class="alignleft"><?php next_posts_link('? Older Entries') ?></div> <div class="alignright"><?php previous_posts_link('Newer Entries ?') ?></div> </div> <?php endif; get_footer(Credits); ?>
Note: that the only reason you really need a specific template for this is that you are wanting a different number of posts displayed for taxonomies than you specify in your Settings->Reading->Blog pages show x posts.
Thanks again, unfortunately that is giving me the same error. It will work linking to one previous page, but then anything after that it says it can’t be found.
PS: I have to use a different template because I do a lot of stuff with this site and have a number of templates that display different content in different ways.
Actually I think this is going to work. I deleted my template to see if it would work with the default archive.php file as it’s template, to see if there was a greater problem, and it worked.
Then I put my template back in (with your recent code), but WordPress wasn’t recognizing the template, like it does sometimes, so I did that trick of visiting the permalinks page and then it recognized it, and the links started working.
Link to see the problem might be useful.
It’s installed locally right now, I don’t want to put anything online until I get everything working. Your code seems to be working now though. Would there be much difference using this to query posts from a custom post type?
Im currently using this to query the posts but it still needs working pagination also.
If you are creating your own template to display posts/custom posts you need to use the paged query var and the next/previous posts link code.
Disable all plugins, switch to the twentyten theme. Update your permalinks to use the Default permalinks. In single.php put this line after
the_content()
(line 30) and put your custom taxonomy name in place of genre.<?php echo get_the_term_list( $post->ID, 'genre', '<p>Genre: ', ', ', '</p>' ); ?>
Then visit a single post, click on the taxonomy link and see if pagination works.
Thanks. There is a lot of that I can’t do though. I need to keep the same theme, I need to keep the /%postname%/ permalink structure, and I need to keep my single.php posts separate from this section of the site.
Is that the only way you can use custom posts?
Okay, just trying to make sure paging works in your environment for those conditions.
Maybe someone else will have some other solutions.
Is that the only way possible to paginate custom posts? If you have to use the same template for all post types that kind of defeats the purpose of even having them.
- The topic ‘Taxonomy Pagination’ is closed to new replies.