Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress Pagination with this Query

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #30108
    Linden
    Member

    I’ve been using this query now for a while to get post titles and excerpts outside the loop. Does anyone know if there’s a way to amend the snippet I’m using to add pagination so that after so many post excepts are shown they’d break to another page if there are any more?

    	
    $myposts = new WP_Query();
    $myposts->query('cat=8&showposts=1');

    if ($myposts->post_count == 0) { ?>

  • while ($myposts->have_posts()) : $myposts->the_post(); ?>

    Featured Match



    ">





    "alignleft post_thumbnail")); } ?>




    } ?>

    Thank you!

    #80875
    Darfuria
    Member

    Add the below to the end of your query:

    &paged=' . get_query_var('paged')); ?>
    #80876
    Linden
    Member

    Thanks for that, I tried adding it like this but it doesn’t work, have I inserted it in the wrong place/way?

      

    query('cat=6&showposts=50&paged=' . get_query_var('paged')); ?>

    have_posts()) : $recent->the_post(); ?>




    • ">
      (Posted on )




    #80826
    Darfuria
    Member

    You might need to substitute

    showposts=50

    With

    posts_per_page=10

    Of course, you will also need to add in your previous/next page links after your endwhile;

    #76539
    Linden
    Member

    I found a solution that seems to work nicely (I couldn’t get it to work with the other query). Here’s the code for anyone who wants to achieve the same thing.


      $temp = $wp_query;
      $wp_query= null;
      $wp_query = new WP_Query();
      $wp_query->query('cat=6&showposts=50'.'&paged='.$paged);
      ?>
      have_posts()) : $wp_query->the_post(); ?>
    • " rel="bookmark">



Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.