1

我有个问题。我想用这段代码显示一次一篇文章和一次 5 篇文章,但他显示了两个不必要的文章。我不明白的是,它是我的另一个具有相同主题的网站确实有效。完全相同的主题只有其他网站。谁能帮我?!(检查错误结果http://radiozuid.com/一个 websie 正确结果http://radiozuid.rtv-zuid.com/beta/)(完全相同的主题)

            <?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();
            ?>
4

1 回答 1

4

问题是您的查询返回的是粘性帖子,无论出于何种原因,这些帖子都被附加到帖子限制中,而不是计入其中。添加ignore_sticky_posts到您的查询中,我认为这将解决它。

$the_query = new WP_Query(array(
    'posts_per_page' => 5, 
    'offset' => 1,
    'ignore_sticky_posts' => true
));
于 2013-02-12T15:40:09.593 回答