• Resolved Andris

    (@andrisibl)


    Hi friends

    I trying to make the homepage of my blog paged, but the 2nd page shows the same entries as the first page. Does anyone have an idea, where this comes from?

    here’s my query:

    <?php if (have_posts()) : ?>
    <?php $header_query = new WP_Query( 'post_type=post&orderby=date&order=DESC&showposts=1' ); ?>
    <?php while ( $header_query->have_posts() ) : $header_query->the_post(); ?>
    <?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
    
    <div class="home-header" style="background:url(<?php echo $url; ?>) center center; background-size:cover;">		
    		
    		<div class="home-field">
    			<h3><?php the_time( get_option( 'date_format' ) ); ?></h3>
    			<h3 class="kategorien"><?php the_category(' | '); ?></h3>
    	        <div class="clear"></div>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <?php the_excerpt(); ?>
    		</div><!-- end home-field -->		
    		
    </div><!--  end home-header -->		
    
    <?php endwhile; ?>
    
    <div id="main" class="home">
       <div class="teaserposts">
    <!-- Zeige die Posts als Liste -->			
    	<?php $list_query = new WP_Query( 'post_type=post&orderby=date&order=DESC&offset=1&paged=paged' ); ?>
    	<?php while ( $list_query->have_posts() ) : $list_query->the_post(); ?>
    	     	
            <div class="teaserpost">
                
                <div class="teaser-bild">
                	<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('quadrat'); ?></a>
                </div><!-- end teaser-bild -->
                  
                <div class="teaser-text">
    	            <h3><?php the_time( get_option( 'date_format' ) ); ?></h3>
    	            <h3 class="kategorien"><?php the_category(' | '); ?></h3>
    	            <div class="clear"></div>
                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    <?php the_excerpt(); ?>
                </div><!-- end teaser-text -->
                
                <div class="clear"></div>
                
            </div><!-- end teaserpost -->
    	
    	<?php endwhile; ?>
    	
    	
    		
    	<div class="navigation">
    		<div class="alignleft nav-links" ><?php previous_posts_link('&laquo; Previous Entries') ?></div>
    		<div class="alignright nav-rechts"><?php next_posts_link('Next Entries &raquo;','') ?></div>
     	</div><!-- end navigation -->
    	
    	<?php rewind_posts(); ?>
    	
    	</div><!-- end teaserposts -->
    		
    <?php endif;?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Your query needs to use the proper pagination parameters. Right now your offset is fixed as “1”, and paged=paged accomplishes nothing. You can get the proper paged query var from the original main query, but it must be done as one of the first things on your template. This value becomes unreliable once you start making your own queries.

    As noted in the linked doc, using offset breaks the default pagination, which is OK because you are not using it any way. Do follow the workaround link in the offset description for how to handle this.

    Thread Starter Andris

    (@andrisibl)

    Thanx @bcworkz for your reply.

    I tried to follow your suggestion but couldn’t make it work. I also tried to make the pagination work without the offset, but couldn’t make it work, too. So maybe it’s not the offset that breaks the pagination but something else or a combination of both.

    The category page also shows the same entries on page 2. Where I don’t use the offset parameter:

    <?php if (have_posts()) : 
    		query_posts(array('category_name' => single_cat_title( '', false ))); ?>
    		<?php while (have_posts()) : the_post(); ?>
    	     	
                <div class="teaserpost">
                
                  <div class="teaser-bild">
                  	<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('quadrat'); ?></a>
                  </div><!-- end teaser-bild -->
    			  
                  
                  <div class="teaser-text">
    	              <h3><?php the_date(); ?></h3>
    	              <h3 class="kategorien"><?php the_category(' | '); ?></h3>
                      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                      <?php the_excerpt(); ?>
                  </div><!-- end teaser-text -->
                
                  <div class="clear"></div>
                
                </div><!-- end teaserpost -->
            
    	<?php endwhile; ?>
    	
    		<?php posts_nav_link(); ?>	
     	
    	<?php endif;?>
        <?php wp_reset_query(); ?>
    

    I’m lost.

    Thread Starter Andris

    (@andrisibl)

    I finally made it almost work.

    I’m just not sure how I can assign this workaround to the specific query.

    There are two queries. One for the first post, which is dispplay differently than the others and one for the rest. I just don’t wanna display the first post again in the second query. So the workaround assigns the function to the is_home() query.

    if ( ! $query->is_home() ) {
            return;
        }

    What if I wanna have this function only on my $list_query, which looks like this, right now:

    <?php $list_query = new WP_Query( array('post_type' => 'post', 'orderby' => 'date', 'order' => 'DESC', 'paged' => $paged) ); ?>
    	<?php while ( $list_query->have_posts() ) : $list_query->the_post(); ?>
    	     	
            <div class="teaserpost">
                
                <div class="teaser-bild">
                	<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('quadrat'); ?></a>
                </div><!-- end teaser-bild -->
                  
                <div class="teaser-text">
    	            <h3><?php the_time( get_option( 'date_format' ) ); ?></h3>
    	            <h3 class="kategorien"><?php the_category(' | '); ?></h3>
    	            <div class="clear"></div>
                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    <?php the_excerpt(); ?>
                </div><!-- end teaser-text -->
                
                <div class="clear"></div>
                
            </div><!-- end teaserpost -->
    	
    	<?php endwhile; ?>
    
    Thread Starter Andris

    (@andrisibl)

    Just to let you guys know:

    I resolved my problem with another solution. I like to call it the ?do_not_duplicate?-method.

    Here’s my first query:

    <?php if (have_posts()) : ?>
    <?php $header_query = new WP_Query( array('post_type' => 'post', 'post__not_in' => $do_not_duplicate, 'orderby' => 'date', 'order' => 'DESC', 'showposts' => '1' ) ); ?>
    <?php while ( $header_query->have_posts() ) : $header_query->the_post(); 
    	$do_not_duplicate[] = $post->ID;
    ?>
    
    <!-- Enter Stuff here -->	
    
    <?php endwhile; endif; ?>
    
    <?php wp_reset_query(); ?>

    And here’s the second query:

    <?php if (have_posts()) : ?>
    	<?php $list_query = new WP_Query( array('post_type' => 'post', 'post__not_in' => $do_not_duplicate, 'orderby' => 'date', 'order' => 'DESC', 'paged' => $paged ) ); ?>
    	<?php while ( $list_query->have_posts() ) : $list_query->the_post(); 
    		$do_not_duplicate[] = $post->ID;
    	?>
    	     	
    <!-- Enter some other Stuff here -->
    	
    	<?php endwhile; ?>
    			
    	<div class="page-navigation">
    	<?php posts_nav_link(); ?>		
    	</div><!-- end page-navigation -->
    	
    	</div><!-- end teaserposts -->
    		
    <?php endif;?>	
    
    <?php wp_reset_query(); ?>

    That totally did the trick for me. Hope it helps, if anyone else has the same problem.

    Cheers.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘page 2 shows same entries as page 1’ is closed to new replies.