Support » Plugins and Hacks » Category Pagination bizarreness?

  • I am having an issue with my category pages. First off, the category page is named category-6.php, in case that matters. Here’s how I am calling my posts:

    <?php query_posts('cat=6,5,4'.get_option('posts_per_page')); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    However, pagination isn’t showing up at all. I’ve tried to implement some changes as shown here:

    and the pagination link shows up for previous posts, but when I click the link it takes me to, which shows exactly the same post summaries as are on the previous page. Here is my code:

    <div class="navigation">
    	<div class="alignleft"><?php next_posts_link('&laquo; Previous Entries') ?></div>
    	<div class="alignright"><?php previous_posts_link('Next Entries &raquo;') ?></div>
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    <?php query_posts('cat=6,5,4&paged=$paged'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    I need to get pagination working properly on these category pages. Does anyone have any solutions I’ve missed?

Viewing 15 replies - 1 through 15 (of 20 total)
  • Read carefully the Usage section!


    Thanks for the pointer. The problem is that I’ve read this page as well as many others very carefully, and while I seem to find what I need fairly quickly when customizing WP this particular case seems to be different. I have found many many different approaches both in Codex as well as from other users, though none of them satisfy my needs properly.

    I have tried to be very specific in my post. If there is something I am missing, can you please return the respect and be specific in your replies? I realize this may be a simple oversight, but I would not have posted here if I had not searched for a solution to this problem for many hours already.

    Thank you.

    That whole section I was referring to has 4-5 lines alltogether.

    Place a call to query_posts() in one of your Template files before The Loop begins. The wp_query object will generate a new SQL query using your parameters. When you do this, WordPress ignores the other parameters it receives via the URL (such as page number or category). If you want to preserve that information, you can use the variable $query_string in the call to query_posts().

    For example, to set the display order of the posts without affecting the rest of the query string, you could place the following before The Loop:

    query_posts($query_string . “&order=ASC”)

    I think that $query_string part might help…

    Ok, thank you. I’m trying to implement this right now, but can you elaborate on how I might
    A) Call specific categories
    B) Paginate
    C) Use the links for next/previous pages?

    My efforts don’t seem to yield a properly paginated result. All that happens when I click on next or previous is that it navigates to “(url)/page/2”, “(url)/page/3”, etc, but it shows the same post on each page. (If I set “&posts_per_page=-1” it shows 3 distinct articles, one from each category, which is how many I have currently for testing).


    I know this post might seem daft, but I cannot get the categories to paginate correctly while I am calling multiple categories. Can anyone share examples of how they have successfully achieved this? Again, my needs are these:

    I need the code to:
    A) Call specific categories (“cat=6,5,4”)
    B) Paginate after a set number of posts (in this case 5)
    C) Show proper links (that work) for next/previous

    Have you figured out how to do this on your category pages? Would you mind posting the lines of code as an example of how you’ve gotten it to work? I’m sure it’s quite simple, but I’ve tried many a combinations, and everything either dismisses the next/previous links (they don’t show up at all), or they only navigate to a new page with the same posts as page 1.

    Any help is greatly appreciated…

    Err.. moshu gave you the answer, 2 days ago. All you have to do is to actually READ it. It’s not complicated.

    However, just so you’ll stop posting the same question over and over:


    Was that really so hard to figure out?


    I’m sorry that you have mistaken me for an ignorant tard that can’t wipe my own nose. That is not the case. Please don’t assume that I am just leeching simply because I’m asking a simple question. I know this is a simple problem, and I’m quite familiar with wordpress. However, I have tried what you have posted, as well as many other combinations to this effect, and nothing has worked. I just posted your code above my loop, and this is one of the worst attempts, in that it doesn’t even return any data from the database. Now, maybe I’m missing some other OBVIOUS code that needs to be used in conjunction with this, or maybe there’s a bug somewhere. Either way, I’m asking a legitimate question, needing legitimate help, and I’m getting nothing but backlash in the responses.

    Please tell me I’m missing something so obvious it’s silly, and tell me what that is. Otherwise, please give me some respect by not assuming that I’m just being lazy.

    Thank you.

    By the way, is the $query_string variable meant to be employed when the query string already has info that is pertinent to the results being displayed? What I mean is, my understanding was that having $query_string in the query_posts was in cases such as when someone performs a search and wants to use that search criteria in the query on this new page, for example. Am I mistaken?

    Am I mistaken?

    Yes. Having the query_string in your query means that you are modifying the existing query string instead of replacing it. Since that’s what you want to do (change it to be those categories), then that would be the correct way to do it.

    Please tell me I’m missing something so obvious it’s silly, and tell me what that is. Otherwise, please give me some respect by not assuming that I’m just being lazy.

    Well, clearly you are missing something obvious, but since what you’re telling me is at odds with, you know, reality and such, then we can’t exactly help out much.

    See, the code I gave you is correct. Just replace your own query_posts in the code you posted earlier with that code. That’s all there is to it. All that crap you’re doing with the “paged” is unnecessary. If you didn’t get any posts back, then you did something wrong. I can’t tell you what, because I am not yet gifted with the power of knowing everything that happens in all places.

    In other words, I can’t tell you what you’re doing wrong without knowing what exactly you’re doing. I can only tell you what the right answer is, and I’ve already done that.

    Additional: You can also add “&showposts=5” to the end of that query, to get the 5 posts per page that you’re talking about as well.

    Thank you for your response. Unfortunately, there still seems to be a disconnect. Here’s what I have in my code (I have removed any additional info, such as xhtml styling, and postmeta stuff for simplicity):

    <?php posts_nav_link(); ?>
    				<?php query_posts($query_string.'&cat=6,5,4'); ?>
    				<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    					<?php the_title(); ?>
    					<?php echo the_excerpt_rss(); ?>
    					<?php endwhile; ?>
    				<?php posts_nav_link(); ?>
    				<?php endif; ?>

    Nothing shows up. All I get is one line that gives the category title of that category page, which is “Featured Articles”. No posts, no titles, no pagination navigation, nothing.

    Now, if I change the query_posts line to omit the $query_string variable, (as below), then I get the posts to show up as expected, but when I click on previous or next page, I get the exact same results as the first page. I never see the additional posts. Here’s the code that works (somewhat):

    <?php posts_nav_link(); ?>
    				<?php query_posts('cat=6,5,4'); ?>
    				<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    					<?php the_title(); ?>
    					<?php echo the_excerpt_rss(); ?>
    					<?php endwhile; ?>
    				<?php posts_nav_link(); ?>
    				<?php endif; ?>

    I’ve removed anything else that could cause a conflict, and nothing makes a difference. Is there anything else I can look at?

    Thank you.

    … Is this in some weird other file, like header.php or something? Or inside a function call?

    Try adding “global $query_string;” just before your call to query_posts.


    I tried adding that line. Even when I remove EVERYTHING except the lines I’ve posted above, and the template comments, (no header, no footer, no sidebar, etc), I still get the same results as I’ve posted earlier, indicating to me it’s nothing in my code that’s conflicting, at least not on the page itself.

    So, other details:
    -Category “Featured Articles” set up in the categories section under “Manage”.
       » Category Parent: none
    – Category PAGE set up titled “Featured Articles”
       » Page Parent: Main Page (no parent)
       » Page Template: “Category 6 Page – Featured Articles” (shows up correctly)
    – Corresponding PHP file name: category-6.php

    Is something amiss here? Is this a WP bug? Are there any additional details I can share?

    Thank you.

    You are mixing everything big time…

    Page Templates and Category_Templates shouldn’t be mixed together.

    A Page template is not meant to show multiple posts. Also, a specific category template file (category-6.php) shouldn’t be used as a Page template.

    Whatever you are trying to do – it’s getting more and more confusing.

    P.S. “global $query_string;” didn’t seem to do anything, on either set of code…

    A Page template is not meant to show multiple posts.

    Why? An archive file is listing multiple posts, is it not?

    From the Page Template codex page:

    archives.php – ignores Page content and instead displays a list of Archives by Month and Archives by Subject (by Category)

    Is there somewhere that this is indicated that a page cannot be used for a category file? I’m clearly confused, but I don’t realize yet why…

    Thank you for your patience and help in getting me set straight…

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Category Pagination bizarreness?’ is closed to new replies.