WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pagination loop issue (3 posts)

  1. localretard
    Member
    Posted 3 years ago #

    I have the reading settings in the admin set to only show 2 posts. I also have a query in the global loop to exclude some categories:

    query_posts("&cat=-179,-4,-70,-19" ); This query will be on the front page

    and I'm trying to continue that loop on other pages because I only want that those specific posts to show and I want more than just two to show. So the code is:

    query_posts($query_string . "&posts_per_page=10" );

    Now what is happening is the frontpage works, however it seems to always get screwed up during the pagination. What am I doing wrong?

    Here is the simplistic version of the code:

    <?php if ( $paged < 2 ) { // Do stuff specific to first page?>
    
    <?
    query_posts("&cat=-179,-4,-70,-19" );
    while ( have_posts() ) : the_post();
    
    ?>
    
    <?php the_title(); ?>
    
    <?php endwhile; ?>
    
    <? } else { ?>
    
    <?
    
    query_posts($query_string . "&posts_per_page=10" );
    while (have_posts()) : the_post();
    ?>
    
    <?php the_title(); ?>
    
    <?php endwhile; ?>
    
    <? } ?>
  2. vtxyzzy
    Member
    Posted 3 years ago #

    Here is an article I wrote with a code example of how to implement a short first page.

  3. localretard
    Member
    Posted 3 years ago #

    Thanks that actually did help.

    For anyone else with the same or similar issue, I had to customize it around my paging code as so:

    <?php
     $max_first_page = 2;  // Show this many posts on front page
          $args = $wp_query->query;
          $args['caller_get_posts'] = 1; // Using stickies messes up the count
          $args['cat'] = '-179,-4,-70,-19';
          $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
          $posts_per_page = get_query_var('posts_per_page');
          $posts_to_skip = $posts_per_page - $max_first_page;
          if ($page == 1) {
             $max_posts = $max_first_page;
          } else {
             $max_posts = $posts_per_page;
             $args['offset'] = (($page - 1) * $max_posts)- $posts_to_skip;
          }
          query_posts($args);
          if ($wp_query->max_num_pages < ceil(($wp_query->found_posts + $posts_to_skip)/$posts_per_page))
            ++$wp_query->max_num_pages;
          $counter = 0;
          ?>
    
    <? if ( $paged < 2 ) { // Do stuff specific to first page?>
    
    while (have_posts()) : the_post();
             if (++$counter > $max_posts) continue;
    
    <? the_title(); ?>
    		<br/>
    <? endwhile; } else { ?>
    
    <? while (have_posts()) : the_post(); if (++$counter > $max_posts) continue; ?>
    
    <? the_title(); ?>
    			<br/>
    <? endwhile; } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic