Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在wordpress中显示有限数量的帖子_Wordpress - Fatal编程技术网

在wordpress中显示有限数量的帖子

在wordpress中显示有限数量的帖子,wordpress,Wordpress,我已经显示了“新闻”类别的帖子 它正在显示所有帖子,但如何仅显示最近的3篇帖子 这是我的密码 <div class="pt-news"> <?php query_posts('cat=7','order=DSC');?> <?php $i=1; while( have_posts() ): the_post(); ?> <div class="pt-newsdesc"> <fig

我已经显示了“新闻”类别的帖子

它正在显示所有帖子,但如何仅显示最近的3篇帖子

这是我的密码

<div class="pt-news">
    <?php query_posts('cat=7','order=DSC');?>
    <?php $i=1;
    while( have_posts() ): the_post(); ?>
        <div class="pt-newsdesc">
            <figure class="pt-post">
            <?php echo the_post_thumbnail(); ?>
            </figure>
            <div class="pt-content"><?php the_content();?>
                <a class="more-link" href="<?php the_permalink();?>"><?php _e('Read More');?></a>
            </div>
        </div>
        <?php 
        $i++;
        endwhile;
        ?>
</div>

您可以尝试将while循环调整为:

<?php $i = 1; while (have_posts() && $i < 3) : the_post(); ?>


这应该限制为3篇文章。

您可以尝试将while循环调整为:

<?php $i = 1; while (have_posts() && $i < 3) : the_post(); ?>


这应该限制为3篇文章。

显示每页使用的有限文章数
posts\u
with
query\u posts()
中,像下面这样传递参数数组

<?php query_posts(array('cat'=>7,'order'=>'DSC','posts_per_page'=>3));?>

或者您可以像下面这样传递查询字符串

<?php query_posts('cat=7&order=DSC&posts_per_page=3');?>

在此之后,输入while循环代码(无需检查自动增量变量)


显示每页使用的有限帖子数量
posts\u
with
query\u posts()
中,像下面这样传递参数数组

<?php query_posts(array('cat'=>7,'order'=>'DSC','posts_per_page'=>3));?>

或者您可以像下面这样传递查询字符串

<?php query_posts('cat=7&order=DSC&posts_per_page=3');?>

在此之后,输入while循环代码(无需检查自动增量变量)



在参数中使用每页帖子。使用此选项。但这将显示所有poststry this$the_query=new WP_query(数组('category_name'=>'news','posts_per_page'=>3));实际上,这是一个疑问,在哪里使用每页文章?必须在post参数数组中使用每页文章。在参数中使用每页文章。使用此选项。但这将显示所有poststry this$the_query=new WP_query(数组('category_name'=>'news','posts_per_page'=>3));实际上,这就是querry,在哪里使用每页post?您必须在post参数数组中使用每页post。这非常好。酷。:)非常好。酷。:)