【发布时间】:2018-03-09 21:16:58
【问题描述】:
在我的 wordpress 头版中,我使用 query_posts 来显示博客中的帖子。
但是,我认为使用 query_posts 是一种不好的做法,因此我正在使用 WP_query 重写代码。问题是 WP_query 仅在我执行此操作时返回当前页面,而不管我明确告诉 wordpress 查找帖子而不是页面这一事实:
<?php $que = new WP_query(array('post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>2));
if(have_posts()): while(have_posts()): the_post(); ?>
<a href="<?php the_permalink(); ?>">
<p class="date">
<?php the_date();?>
</p>
<h4>
<?php the_title();?>
</h4>
</a>
<?php endwhile; endif;?>
【问题讨论】: