Wordpress: Get links to all posts on one page

2019-07-23 16:40发布

I'd like to add to my blog a page that contains links to all the posts in the blog. Not only 10 in a page or something, but all of them (if that's a bad idea I'd be interested to know why).

Besides links, the name of each post and its date would be nice as well.

标签: wordpress
2条回答
劳资没心,怎么记你
2楼-- · 2019-07-23 16:59

Something like this should do it;

<?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; ?>

Note that the default 'orderby' parameter for get_posts() is actually 'post_date'. I've just added it in for clarity. Have a look here for how to configure the_date().

I agree, with the comment above about pagination. If you have a lot of posts, it might become unwieldy.

查看更多
劫难
3楼-- · 2019-07-23 17:05

There are many ways to do this, but I find the get_posts() function to be the easiest.

This would indeed be a bad idea if you have a lot of posts, and since in most cases you don't know how many you might eventually have, I would at least provide some sort of pagination.

查看更多
登录 后发表回答