WordPress.org

Ready to get started?Download WordPress

Forums

Category Pagination bizarreness? (21 posts)

  1. macwise
    Member
    Posted 5 years ago #

    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:

    http://wordpress.org/support/topic/57912#post-312858

    and the pagination link shows up for previous posts, but when I click the link it takes me to http://www.mysite.com/featured-articles/page/2/, 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>
    </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?

  2. moshu
    Member
    Posted 5 years ago #

    Read carefully the Usage section!
    Template_Tags/query_posts

  3. macwise
    Member
    Posted 5 years ago #

    Moshu,

    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.

  4. moshu
    Member
    Posted 5 years ago #

    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...

  5. macwise
    Member
    Posted 5 years ago #

    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).

    Thanks!

  6. macwise
    Member
    Posted 5 years ago #

    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...

  7. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    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:

    query_posts($query_string.'&cat=6,5,4');

    Was that really so hard to figure out?

  8. macwise
    Member
    Posted 5 years ago #

    Otto,

    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.

  9. macwise
    Member
    Posted 5 years ago #

    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?

  10. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    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.

  11. macwise
    Member
    Posted 5 years ago #

    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.

  12. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    ... 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.

  13. macwise
    Member
    Posted 5 years ago #

    Otto,

    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.

  14. moshu
    Member
    Posted 5 years ago #

    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.

  15. macwise
    Member
    Posted 5 years ago #

    P.S. "global $query_string;" didn't seem to do anything, on either set of code...

  16. macwise
    Member
    Posted 5 years ago #

    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...

  17. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    Wait a minute. You're doing this in a PAGE template? Oh. Well, there is your problem. You said originally that it was "category-6.php" which would have worked. That's a category template. You don't make a bloody PAGE for it, it gets a page automatically at /category/whatever/...

    You should never try to display Posts on a Page. There's no reason for it, and when you try doing weird things like that, then yes, our answers won't be right because we don't ever take into account crazy people doing crazy things.

    No guarantees that this will work, because the idea of putting Posts on Pages is a dumb one to begin with, but...

    <?php
    $page = (get_query_var('page')) ? get_query_var('page') : 1;
    query_posts("cat=6,5,4&page=$page");
    ?>
  18. moshu
    Member
    Posted 5 years ago #

    There is archive.php and there is archives.php - the first one displays multiple posts (in monthly and cat archives), the second one is displaying a list, usually generated by the get_archives tag and not a loop! So, no they work completely differently!

    It is nonsense to use a Page for category templates when you have a perfectly working system for that. WP recognizes if there is a Page templates and wants to do what is supposed to do with Pages.

  19. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

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

    Yes, but it's not a Page. It's just a page. Note the capital letters?

    A Page, as in "Write->Page" is wholly different than anything else. It's a static entity, separate from all the rest of the hierarchical post structure. It's not meant to display Posts, and it does it extraordinarily badly, as you have discovered.

    Everything else in WordPress is not a Page, and can display Posts just fine.

  20. macwise
    Member
    Posted 5 years ago #

    Ok, thank you, Otto and Moshu. I'm sorry for confusing that and taking us on this long roundabout journey, and thank you for taking the time to fill me in on how this should be done.

    Now, I've removed the Page, and have gotten the page category-6.php to show up at (url)/featured-articles/. However, (and please don't hate me), I still seem to have issues with this category page. First of all, the query only displays the article that is in category 6, though the query requests category 4,5, and 6.

    Also, pagination still takes me to (url)/featured-articles/page/2, which brings back a 404 error.

    My code has not changed from my above posts.

    Thank you.

  21. luthan
    Member
    Posted 5 years ago #

    @macwise

    use this when doing the query:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
          query_posts("category_name=XXX&paged=$paged"); ?>

    this worked for me so i hope it does for you as well. the other guys here either didn't know what they were talking about or didn't understand you correctly

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.