WordPress.org

Ready to get started?Download WordPress

Forums

query_posts, offset and pagination (9 posts)

  1. skidevil
    Member
    Posted 3 years ago #

    Unfortunately I discovered that I cant use the parameters offset and page at the same time with a query_posts .

    What I do:

    I call query_posts with following arguments:

    $page = get_query_var('paged');
    $args = array('cat' => $cat, 'posts_per_page' => '6','paged' => $page);

    which works fine. If I add something like 'offset' => '1' the 'paged' parameter has no effect anymore...

    Does anyone know a workaround?

    Regards

  2. stvwlf
    Member
    Posted 3 years ago #

    the recommended code for the 1st line of your code is this
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;

    Not sure it will make a difference in combination with offset but its worth trying.

  3. skidevil
    Member
    Posted 3 years ago #

    Thanks for the advice, but doesn't work...

    Indeed it does not make any difference wether you use:

    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;

    or:

    $page = get_query_var('paged');

    Any other ideas?

  4. MandyWhite
    Member
    Posted 3 years ago #

    Are you adding '&paged=' when you load the next page's url? If not, try it.

  5. skidevil
    Member
    Posted 3 years ago #

    I generate the URLs via the function posts_nav_link()...

    Not sure what you mean, but I dont think thats the problem, coz I got no problem if I do not use the offset parameter. So I dont think the problem has something to do with &paged not being loaded...

  6. alchymyth
    Forum Moderator
    Posted 3 years ago #

    If I add something like 'offset' => '1' the 'paged' parameter has no effect anymore...

    Does anyone know a workaround?

    pagination simply does not work with 'offset' at the same time;

    if the 'offset' is used to avoid the first post to be shown twice, look into the methods of avoiding duplicate posts:

    http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

  7. skidevil
    Member
    Posted 3 years ago #

    Hm, does not solve my actual problem, but thanks for the link!

    The technique used @Multiple Loops in Action brought me to a solution I tested and which worked...

    Is there any special reason why 'offset' and pagination doesnt work togehter?

  8. Creative Slice
    Member
    Posted 3 years ago #

    @skidevil can you post the solution you came up with?

    Thanks!!!

  9. skidevil
    Member
    Posted 3 years ago #

    Sure,

    I wanted to achieve that the first post of each site is displayed different (bigger thumbnail, other font, etc.)

    I did this using two queries. The first query does not makes any trouble at all. First I thought I could use offset and pagination for the second post, but that doesnt work. Instead you use something like:

    <?php $my_query = new WP_Query('category_name=featured&posts_per_page=1');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID; ?>
        <!-- Do stuff... -->
      <?php endwhile; ?>

    and

    <?php if (have_posts()) : while (have_posts()) : the_post();
      if( $post->ID == $do_not_duplicate ) continue;?>
       <!-- Do stuff... -->
      <?php endwhile; endif; ?>

    For explanation read:

    http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

Topic Closed

This topic has been closed to new replies.

About this Topic