在wordpress中显示有限数量的帖子
我已经显示了“新闻”类别的帖子 它正在显示所有帖子,但如何仅显示最近的3篇帖子 这是我的密码在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
<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。这非常好。酷。:)非常好。酷。:)