WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Issue with page navigation with query posts

[Resolved] Issue with page navigation with query posts

  • I am creating a template to get alle posts from category 9 into one page. But I want this also to be paginated, as there will be more than 30-50 posts.

    I have tried several things:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
     $my_query = new WP_Query('cat=9&showposts=5&paged=$paged'; ?>

    and

    <?php query_posts('cat=9&showposts=5&paged=$paged'); ?>

    even

    <?php
    if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
    } elseif ( get_query_var('page') ) {
    $paged = get_query_var('page');
    } else {
    $paged = 1;
    }
    query_posts( array( 'post_type' => 'post', 'paged' => $paged, 'cat'=> 9, 'posts_per_page' => 5 ) );
    ?>

    The pagination stays the same: only 1 page and it shows the 5 posts, but there are several more posts, so it should show the pagination right?

    Any help is gladly appreciated!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator keesiemeijer

    @keesiemeijer

    Is this on a static front page?

    Try it with:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $my_query = new WP_Query('cat=9&posts_per_page=5&paged='.$paged); ?>
    while ( $my_query->have_posts() ) : $my_query->the_post();
    // rest of loop

    Michael

    @alchymyth

    Forum Moderator

    your last block of code is the only one likely to work;

    so it should show the pagination right?

    do you have any next_posts_link() and previous_posts_link() or posts_nav_link() (or any pagination plugins) in your template ?

    http://codex.wordpress.org/Function_Reference/next_posts_link
    etc

    @keesiemeijer, no it is not. Otherwise it would be easier 😀

    I’v tried `<?php
    $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
    $my_query = new WP_Query(‘cat=9&posts_per_page=5&paged=’.$paged); ?>

    <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    `
    But it still shows only page 1 of 1

    @alchymyth
    I have <?php if(function_exists('wp_pagenavi')) : wp_pagenavi(); endif; wp_reset_query();?> as a pagination plugin added yes.

    Moderator keesiemeijer

    @keesiemeijer

    try this: http://scribu.net/wordpress/wp-pagenavi/wpn-2-74.html

    wp_pagenavi( array( 'query' => $my_query ) );

    I have page navigation now, but only with 1 per page :’)

    I’ll paste the complete code, because I can’t see it anymore 🙁

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    [ Please do not bump, it’s not permitted here. ]

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    Ok this gives me the page navigation as it should be/look like, BUT when I click on the 2nd page, it still gives me the results of the first page.

    YESSSS I have found it!!!

    [77 lines of code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    If anyone would like the solution, this is it! :))

    Awesome … the solution, but, bummer, can’t see it … is there no way to create links to the pastebin of the offending code if it gets moderated? As is, this is punishing those who need the answer, not those who broke forum rules … a shame.

    Moderator Andrew Nevins

    @anevins

    Forum moderator

    If you require support beyond that provided within this thread, create your own thread on the issue.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] Issue with page navigation with query posts’ is closed to new replies.
Skip to toolbar