繁体   English   中英

如何在WordPress中显示特定数量的帖子

[英]how to display a specific number of posts in wordpress

这是wordpress的php代码,它显示了类别中最后15个帖子的结果,id为cat = 7 ...在缺少前5个帖子后如何显示10个帖子。我需要显示6-15个帖子,任何一个指南,,

<?php 
        $news = new WP_Query('cat=7&posts_per_page=15');
        if ($news->have_posts() ) :
            $item_number = 0; 
            while ($news->have_posts() ) : $news->the_post(); 
           get_template_part('content'); ?>  
        <?php   endwhile;
       else : ?>
            <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
        <?php endif;?>

您需要在查询中设置offset参数。 它等于您要跳过的帖子数。 您的WP_Query应该类似于:

$news = new WP_Query('cat=7&posts_per_page=15&offset=5');

注意,这可能会破坏分页

暂无
暂无

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

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