WordPress.org

Ready to get started?Download WordPress

Forums

Query posts and Pagination Links Broken (20 posts)

  1. mikedistras
    Member
    Posted 3 years ago #

    Ive searched around for an answer to this and saw a couple of the same posts around with the same problem, but no actual answer unfortunately.

    Problem being I have 3 seperare categories being displayed on 1 page... I would like to make it so that the Main category of the page can be scrolled through to older posts with pagination.

    I put the code in after <?php endwhile ?>, the pagination displayed, and the links worked, however the posts on the page remained the same and didnt change regardless of which page I went to.

    After reading some older posts I have probably used 'query_posts' wrong, so hopefully somebody here can help.

    Im using Query_Posts 3 times like so:

    <?php
    query_posts('category_name=news');
    while ( have_posts() ) : the_post() ?>
    
      // styling here //
    
    <?php endwhile ?>

    Then that is simply repeated on the page with a different category_name.

    Link to site: http://www.thefightlounge.co.uk

    Thanks,

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'category_name' => 'news',
    	'paged' => $paged
    );
    query_posts($args);
    ?>
  3. mikedistras
    Member
    Posted 3 years ago #

    A little more info one where to place the code would be brilliant.

    Do I need to add this to every place ive currently used the Query_Posts?
    Or just on the posts I would like to Paginate?

    With the code above placed just on the main "News" part of the query it looks like this (and doesnt work still)

    [Code moderated as per the Forum Rules. Please use the pastebin]

  4. mikedistras
    Member
    Posted 3 years ago #

    Heres link to current code: http://wordpress.pastebin.com/JZDiK1tX

  5. mikedistras
    Member
    Posted 3 years ago #

    Apologies for posting 3 times. Any toher help available? Or the above code being explained? cheers

  6. keesiemeijer
    moderator
    Posted 3 years ago #

    Problem being I have 3 seperare categories being displayed on 1 page

    What template file is this in?
    Do you use multiple loops?
    Put the full full content of the template file you are using in the pastebin.

  7. mikedistras
    Member
    Posted 3 years ago #

    Pastebin Link : http://wordpress.pastebin.com/tBisk8P2

    This is in the homepage template

  8. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    $wp_query->query('cat=3&showposts=5'.'&paged='.$paged);

    $paged is never defined in this query as per above.....

  9. mikedistras
    Member
    Posted 3 years ago #

    This is with the code added from further up the page, that I think I entered wrong... http://wordpress.pastebin.com/XcPAtR9F

  10. keesiemeijer
    moderator
    Posted 3 years ago #

    Have you tried it with the code esmi gave you?
    Pastebin link: http://wordpress.pastebin.com/5Rgs3udr

  11. mikedistras
    Member
    Posted 3 years ago #

    This is the code asmi gave me: http://wordpress.pastebin.com/XcPAtR9F

    The code you just gave me didnt work either (http://wordpress.pastebin.com/5Rgs3udr)

  12. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    well, now I'm more confused...you have the query on line 17.... and then what looks like a loop starting at 27, but no loop opening (if have posts/while have posts...)

    and no endwhile, so that first loop isn't really a loop....so that may be what throws that pagination

    line 38 and 52 are both nav links, not in a loop

    and the 63 and 81 are queries again, that do have full loop (while have posts/end while) but no pagination in the query.....

  13. mikedistras
    Member
    Posted 3 years ago #

    Rev. Voodoo, Which pastebin link are you referring to? (Theres about 3 different ones above haha).

    Could you please submit the edit on the pastebin too and ill test it out.

  14. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    http://wordpress.pastebin.com/XcPAtR9F
    I was referring to this one

    Which one are you using that you are trying to get functioning correctly?

  15. mikedistras
    Member
    Posted 3 years ago #

    Im trying to get any that will get the pagination to work just on that main 'News' Category...

    I added while ( have_posts() ) : the_post() after query_posts($args); and then the endwhile After the post styling, then the navigation straight after endwhile.

    Still doesnt work... Did i add them in the wrong order/wrong place?

  16. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    http://wordpress.pastebin.com/3EByJMFh
    Something like that for the first loop....

    Thing is I'm not sure why you have double nav, etc for the news section.... Also had to reset the query after that

    Every query should have a reset after it on multiple loops.... there is definitely more work to be done here, just guiding a bit....

  17. mikedistras
    Member
    Posted 3 years ago #

    Oh, no idea why there is double nav in there either, got rid of that anyway now...

    Added the endwhile and endif statements to the other query's on the page, and added wp_reset_query too.

    Also done the first loop as you mentioned however its still doing the same as before... The nav links are displaying, however no content changes.

    Current layout:
    http://wordpress.pastebin.com/jkrkfsx2

  18. mikedistras
    Member
    Posted 3 years ago #

    Any other ideas anybody??

  19. mikedistras
    Member
    Posted 3 years ago #

    This is absolutely winding me up now, haha. having read so many different posts and way to achieve this, yet nothing has really worked.

    This is the link to the page:
    http://www.thefightlounge.co.uk

    I want the "news"/Main section to have the Pagination(next/prev) links that actually work. I dont need the other 2 categories on the right hand side to have pagination on them, just the main news category.

    This is a link to the current code for the page: http://wordpress.pastebin.com/HfM17uXD

    Any help and edits welcome and very appreciated!

  20. itsbarry
    Member
    Posted 3 years ago #

    Just posting to say esmi's solution fixed my pagination issue.

    My simpler query was like this:
    <?php query_posts($query_string . '&cat=-9'); ?>

    and pagination was broken.

    I made some slight mods as I was excluding a category from my normal loop:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'cat' => -9,
    	'paged' => $paged
    );
    query_posts($args);
    ?>

    Note my cat arg excludes category ID 9.

Topic Closed

This topic has been closed to new replies.

About this Topic