0
如何返回特定类别中最近X次的帖子?我看过WP_Query(),但不确定需要哪些参数。如何按类别获取最近的X帖子?
如何返回特定类别中最近X次的帖子?我看过WP_Query(),但不确定需要哪些参数。如何按类别获取最近的X帖子?
我会用这样的
参考:http://codex.wordpress.org/Template_Tags/get_posts
<?php
global $post;
$args = array('numberposts' => 3, 'category' => 1);
$lastposts = get_posts($args);
foreach($lastposts as $post) : setup_postdata($post); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
<?php endforeach; ?>
谢谢。代码执行但无论我使用哪个类别,它总是返回当前页面,这是我测试代码的地方。任何想法可能是错误的? – 4thSpace 2013-03-16 03:07:40
我正在使用正确的catID,并在另一页上尝试了此操作。仍然会返回当前页面。 – 4thSpace 2013-03-16 03:17:33
我更新了我的答案。我只是测试和工作。您应该能够将类别标题放在单引号中,而不是类别编号 – 2013-03-16 04:21:51