• 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

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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.

    Thread Starter skidevil

    (@skidevil)

    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?

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

    Thread Starter skidevil

    (@skidevil)

    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…

    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

    Thread Starter skidevil

    (@skidevil)

    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?

    Creative Slice

    (@creativeslice)

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

    Thanks!!!

    Thread Starter skidevil

    (@skidevil)

    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

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘query_posts, offset and pagination’ is closed to new replies.