2013-03-15 68 views

回答

1

我会用这样的

参考: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; ?> 
+0

谢谢。代码执行但无论我使用哪个类别,它总是返回当前页面,这是我测试代码的地方。任何想法可能是错误的? – 4thSpace 2013-03-16 03:07:40

+0

我正在使用正确的catID,并在另一页上尝试了此操作。仍然会返回当前页面。 – 4thSpace 2013-03-16 03:17:33

+0

我更新了我的答案。我只是测试和工作。您应该能够将类别标题放在单引号中,而不是类别编号 – 2013-03-16 04:21:51