WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Issue with page navigation with query posts (10 posts)

  1. mukie
    Member
    Posted 2 years ago #

    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!

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    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
  3. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    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

  4. mukie
    Member
    Posted 2 years ago #

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

    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.

  5. keesiemeijer
    moderator
    Posted 2 years ago #

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

    wp_pagenavi( array( 'query' => $my_query ) );
  6. mukie
    Member
    Posted 2 years ago #

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

  7. mukie
    Member
    Posted 2 years ago #

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

  8. mukie
    Member
    Posted 2 years ago #

    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! :))

  9. 10sexyapples
    Member
    Posted 1 year ago #

    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.

  10. Andrew
    Forum Moderator
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic