RadioZuid Redactie
RadioZuid Redactie

Reputation: 13

wordpress posts_per_page incorrect display

I have a problem. I would like to show one time one post and one time 5 posts with this code but he shows two porst more than necessary. What I don't get, is that it's another site of me with the same theme does work. The completely same theme only a others website. Who can help me?! (check the wrong result http://radiozuid.com/ an websie correct result http://radiozuid.rtv-zuid.com/beta/ ) (Exact same theme)

            <?php 
                $the_query = new WP_Query(array(
                'posts_per_page' => 1 
                )); 
                while ( $the_query->have_posts() ) : 
                $the_query->the_post();
            ?>
            <div class="item active">
                <?php if(has_post_thumbnail()): ?>
         <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'small-nivo-thumb'); ?>
         <img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo $image[0]; ?>&amp;w=620&amp;h=350" class="postafbeelding" alt="<?php the_title(); ?>">
                <?php else: ?>
         <img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo get_template_directory_uri(); ?>/images/thumbnail.png&amp;w=620&amp;h=350" class="postafbeelding" alt="<?php the_title(); ?>">
                <?php endif; ?>
                <div class="carousel-caption">
                    <h3 class="titel"><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h3>
                    <p><?php echo string_limit_words(get_the_excerpt(), 35); ?>...<a href="<?php the_permalink(); ?>" rel="tooltip" data-original-title="Lees Meer" class="leesmeer"> Lees Meer</a></p>
            </div>
        </div>

            <?php 
                endwhile; 
                wp_reset_postdata();
            ?>
            <?php 
                $the_query = new WP_Query(array(
                'posts_per_page' => 5, 
                'offset' => 1 
                )); 
                while ( $the_query->have_posts() ) : 
                $the_query->the_post();
            ?>
            <div class="item">
                <?php if(has_post_thumbnail()): ?>
         <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'small-nivo-thumb'); ?>
         <img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo $image[0]; ?>&amp;w=620&amp;h=350" class="postafbeelding" alt="<?php the_title(); ?>">
                <?php else: ?>
         <img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo get_template_directory_uri(); ?>/images/thumbnail.png&amp;w=620&amp;h=350" class="postafbeelding" alt="<?php the_title(); ?>">
                <?php endif; ?>
                <div class="carousel-caption">
                    <h3 class="titel"><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h3>
                    <p><?php echo string_limit_words(get_the_excerpt(), 35); ?>...<a href="<?php the_permalink(); ?>" rel="tooltip" data-original-title="Lees Meer" class="leesmeer"> Lees Meer</a></p>
                </div>
            </div>
            <?php 
                endwhile; 
                wp_reset_postdata();
            ?>

Upvotes: 1

Views: 1160

Answers (1)

s_ha_dum
s_ha_dum

Reputation: 2850

The problem is that your query is returning sticky posts, which for whatever reason are tacked onto the post limit rather than counting as part of it. Add ignore_sticky_posts to your query and I think that will fix it.

$the_query = new WP_Query(array(
    'posts_per_page' => 5, 
    'offset' => 1,
    'ignore_sticky_posts' => true
));

Upvotes: 5

Related Questions