简体   繁体   English

showposts和posts_per_page都无法在我的主页上运行

[英]showposts and posts_per_page both not working on my home page

Have a homepage, things are coming along great. 有一个主页,一切进展顺利。

but the home page is supposed to show 1 post from each designated category... it's showing more... 但首页应该在每个指定的类别中显示1条帖子。

tried using showposts, and posts_per_page, with no success 尝试使用showposts和posts_per_page,但没有成功

here's a copy of the page with both being used to no avail: 这是页面的副本,两者均无济于事:

have_posts()) : $mb_recent->the_post(); have_posts()):$ mb_recent-> the_post(); $more = 0; $ 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> 

I had this problem as well using both "showposts" and "posts_per_page". 我同时使用“ showposts”和“ posts_per_page”也遇到了这个问题。 It was solved for me as soon as I added "ignore_sticky_posts". 添加“ ignore_sticky_posts”后,它立即为我解决了。

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

I'm not sure what the variables $mb_blog and $mb_blog_home contain but I'm sure they will be causing the issue. 我不确定$ mb_blog和$ mb_blog_home变量包含什么,但是我确定它们会引起问题。

You should just need category and the posts_per_page in your query 您只需要查询中的类别和posts_per_page

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM