WordPress.org

Ready to get started?Download WordPress

Forums

WP Query and Pagination (2 posts)

  1. mahodder
    Member
    Posted 4 years ago #

    I'm trying to implement pagination on my query but it doesn't seem to be working at: http://www.bnoptwitter.nl/

    The query I built takes the most recent post from the categories listed and prints them out - I set WP to display max 1 post for testing and used the code below but it's still showing 3.

    The following code is entered into a page, I then set this page as the homepage using the WordPress options.

    Anyone have any ideas on how to implement pagination correctly?

    <?php
    for ($i = 1; $i <= 3; $i++) {
    if ($i==1) {$oi_cat = "3js";}
    if ($i==2) {$oi_cat = "marco-borsato";}
    if ($i==3) {$oi_cat = "adam-curry";}
    
    //The Query
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $query= 'category_name='.$oi_cat.'&showposts=1'.'&paged='.$paged;
    $recent = new WP_Query($query); while($recent->have_posts()) : $recent->the_post(); 
    
    global $more;    // Declare global $more (before the loop).
    $more = 0;       // Set (inside the loop) to display content above the more tag.
    the_content("Reageer");
    
    endwhile;}
    
    ?>
    <br clear="all">
    <div class="navigation">
      <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div>
      <div class="alignright"><?php next_posts_link('More &raquo;') ?></div>
    </div>
  2. stvwlf
    Member
    Posted 4 years ago #

    Hi

    Some of your code looks like its from the article I'm about to link to - if not, it was taken from something similar.

    In this first article, read the section at the end about using pagination
    http://weblogtoolscollection.com/archives/2008/04/13/define-your-own-wordpress-loop-using-wp_query/

    and then, this article on why paging doesn't work with wp_query
    http://weblogtoolscollection.com/archives/2008/04/19/paging-and-custom-wordpress-loops/

    You should fine your answer here.

Topic Closed

This topic has been closed to new replies.

About this Topic