在WordPress循环中显示摘录然后上一个x帖子数

时间:2010-12-27 21:40:35

标签: wordpress

我想显示在某个类别中发布的最后一篇文章的摘录,然后显示该类别中之前的5篇帖子

 Category Fruit
     Apples
     This is a post about apples. I love apples you know they say an apple a day keeps the doctor away. Stack overflow is the Apple of my eye its a great place to Continue Reading ->

     And a post about oranges
     And a post about grapes
     And a post about bananas

1 个答案:

答案 0 :(得分:0)

这可能会这样做。这将显示最新帖子和之前的4个标题的摘录。

<?php global $post;
$args = array( 'posts_per_page' => 5, 'offset'=> 0, 'category_name' => 'fruit' );
$myposts = get_posts( $args );
foreach( $myposts as $key=>$post ) : setup_postdata($post); 
 if ($key == 0) { ?>
 <a href="<?php the_permalink(); ?>"><?php the_excerpt(); ?></a>
<?php } else { ?>
 <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php } ?>
<?php endforeach; ?>

随意询问如何使其适应您的需求=)