1

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

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

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

这是页面的副本,两者都无济于事:

have_posts()) : $mb_recent->the_post(); $更多 = 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>
4

2 回答 2

9

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

$minposts = new WP_Query( array(
            'posts_per_page'=> 3,
            'ignore_sticky_posts' => 1
        )   
    );      
于 2012-10-16T15:48:26.477 回答
0

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

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

<?php $mb_recent = new WP_Query('cat=5&posts_per_page=1'); ?>
于 2012-07-07T16:24:09.373 回答