Support » Fixing WordPress » query_posts offset issue

  • I’ve done some searching around and I still can’t figure out what is happening. Basically what happens is that Page 1 shows 5 posts, Page 2 shows 10 posts, but there is no link to Page 3 (which should show 2 posts that are remaining). If I manually goto the link, I get an error due to no articles.

    $paged is being set (so it’s not a null value issue).

    This is the query_post structure I’m using (minus a few extra fields like post__not_in and cat, which shouldn’t be effecting it.

    query_posts(
    	array(
    		'posts_per_page'=> ( ( $paged == 1 ) ? 5 : 10 ),
    		'offset'	=> ( ( $paged == 1 ) ? 0 : ( ( $paged - 1 ) * 10 ) - 5 )
    	)
    );

    Totally lost :/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Okay not sure you will want this, but this will show you 5 posts per page, excluding categories 2 and 3:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args=array(
      'category__not_in' => array(2,3),
      'post_per_page' => 5,
      'paged'=> $paged
    );
    query_posts($args);
    ?>

    did you mean that want to show 5 entries in page 1 and the rest are 10 entries ? then use this :

    $current_page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $max_entries_per_page = ($current_page == 1) ? 5 : 10;
    
    query_posts("paged=" . $current_page);
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <!-- BLA BLA BLA BLA -->
    <?php endwhile; ?>
    <?php endif; ?>
    
    <?php next_posts_link('« Older Entries', $max_entries_per_page) ?>
    <?php previous_posts_link('Newer Entries »', $max_entries_per_page) ?>

    if you want to have 10 entries in each page then the :
    $max_entries_per_page = ($current_page == 1) ? 5 : 10;
    change to :
    $max_entries_per_page = 10;

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘query_posts offset issue’ is closed to new replies.