Wordpress:获取一页上所有帖子的链接

时间:2012-01-21 14:07:30

标签: wordpress

我想在我的博客中添加一个页面,其中包含指向博客中所有帖子的链接。不仅是页面中的10个或者其他内容,而是所有这些(如果这是个坏主意我会有兴趣知道原因)。

除了链接,每个帖子的名称及其日期也会很好。

2 个答案:

答案 0 :(得分:7)

这样的事情应该这样做;

<?php
$args = array( 'numberposts' => -1, 'orderby' => 'post_date' );
$postslist = get_posts( $args );
foreach ($postslist as $post) :  setup_postdata($post); ?> 
    <div>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
              <br />  
            <?php the_date(); ?>
            <br />  
          <?php the_excerpt(); ?>
   </div>
<?php endforeach; ?>

请注意,get_posts()的默认'orderby'参数实际上是'post_date'。为了清楚起见,我刚刚添加了它。请查看如何配置the_date()

我同意上面关于分页的评论。如果你有很多帖子,它可能会变得笨拙。

答案 1 :(得分:1)

有很多方法可以做到这一点,但我发现get_posts()函数是最简单的。

如果你有很多帖子,这确实是一个坏主意,因为在大多数情况下你不知道你最终会有多少,我至少会提供某种pagination。< / p>