showposts和posts_per_page都不在我的主页上

时间:2012-07-07 15:15:06

标签: php wordpress

有一个主页,事情进展顺利。

但主页应该显示每个指定类别的1个帖子...它显示更多...

尝试使用showposts和posts_per_page,但没有成功

这是一个页面的副本,两者都被用来无济于事:

    have_posts()):$ mb_recent-> the_post(); $ more = 0; ?>
    <!-- post -->
         <div class="post archive">
        <div class="post-comments"><?php comments_popup_link('0', '1', '%'); ?></div>

    <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
        <div class="post-date"><?php the_time('l, F jS, Y') ?></div>
        <?php if (get_post_meta($post->ID, 'post_image_value', true)) { ?><div class="post-tnail"><a href="<?php the_permalink() ?>"><?php if (get_post_meta($post->ID, 'post_image_value', true) && $mb_resize == 0) { ?><img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo get_post_meta($post->ID, "post_image_value", $single = true); ?>&amp;w=98&amp;h=98&amp;zc=1&amp;q=95" alt="<?php the_title(); ?>" /><?php } else if (get_post_meta($post->ID, 'post_image_value', true) && $mb_resize == 1) { ?><img src="<?php bloginfo('home'); ?><?php echo get_post_meta($post->ID, "post_image_value", $single = true); ?>" alt="<?php the_title(); ?>" /><?php } ?></a></div><?php } ?>

      <?php the_excerpt() ?>
<p><a href="<?php the_permalink() ?>" class="more">Continue reading...    
         </a></p>                       
                    </div>
                    <!-- /post -->

                    <?php endwhile; ?>


                    <?php $mb_recent = new WP_Query('cat=5' . $mb_blog . '&posts_per_page=1' . $mb_blog_home . ''); ?>
                    <?php while ($mb_recent->have_posts()) : $mb_recent->the_post(); $more = 0; ?>

                    <!-- post -->
                    <div class="post archive">
                        <div class="post-comments"><?php comments_popup_link('0', '1', '%'); ?></div>
                        <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
                        <div class="post-date"><?php the_time('l, F jS, Y') ?></div>
                        <?php if (get_post_meta($post->ID, 'post_image_value', true)) { ?><div class="post-tnail"><a href="<?php the_permalink() ?>"><?php if (get_post_meta($post->ID, 'post_image_value', true) && $mb_resize == 0) { ?><img src="<?php echo bloginfo('template_url'); ?>/thumb.php?src=<?php echo get_post_meta($post->ID, "post_image_value", $single = true); ?>&amp;w=98&amp;h=98&amp;zc=1&amp;q=95" alt="<?php the_title(); ?>" /><?php } else if (get_post_meta($post->ID, 'post_image_value', true) && $mb_resize == 1) { ?><img src="<?php bloginfo('home'); ?><?php echo get_post_meta($post->ID, "post_image_value", $single = true); ?>" alt="<?php the_title(); ?>" /><?php } ?></a></div><?php } ?>
                        <?php the_excerpt() ?>
                        <p><a href="<?php the_permalink() ?>" class="more">Continue reading...</a></p>                      
                    </div>

2 个答案:

答案 0 :(得分:9)

我也使用“showposts”和“posts_per_page”来解决这个问题。一旦我添加了“ignore_sticky_posts”,它就为我解决了。

$minposts = new WP_Query( array(
            'posts_per_page'=> 3,
            'ignore_sticky_posts' => 1
        )   
    );      

答案 1 :(得分:0)

我不确定$ mb_blog和$ mb_blog_home包含的变量是什么,但我确定它们会导致问题。

您应该只需要查询中的类别和posts_per_page

<?php $mb_recent = new WP_Query('cat=5&posts_per_page=1'); ?>