Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress - List all posts (with proper_pagination)

Tags:

On the Wordpress site I'm working on, it lists posts by category, but I am also after a page that lists ALL the posts (with pagination, showing 10 per page). How would I go about achieving this?

Thanks

like image 770
Probocop Avatar asked Jan 25 '11 14:01

Probocop


People also ask

How do I get a list of all posts in wordpress?

You have to use post_per_page='-1' to retrive all the posts. $args = array( 'post_type'=> 'post', 'orderby' => 'ID', 'post_status' => 'publish', 'order' => 'DESC', 'posts_per_page' => -1 // this will retrive all the post that is published ); $result = new WP_Query( $args ); if ( $result-> have_posts() ) : ?>


2 Answers

You could create a new page template with this loop in it:

<?php  $paged = get_query_var('paged')? get_query_var('paged') : 1; $args = [     'post_type' => 'post',     'posts_per_page' => 10,      'paged' => $paged, ]; $wp_query = new WP_Query($args);  while ( have_posts() ) : the_post(); ?>     <h2><?php the_title() ?></h2> <?php endwhile; ?>  <!-- then the pagination links --> <?php next_posts_link( '&larr; Older posts', $wp_query ->max_num_pages); ?> <?php previous_posts_link( 'Newer posts &rarr;' ); ?> 
like image 95
Gavin Avatar answered Oct 12 '22 02:10

Gavin


For others who might be Googling this... If you have replaced the front page of your site with a static page, but still want your list of posts to appear under a separate link, you need to:

  1. Create an empty page (and specify any URL/slug you like)
  2. Under Settings > Reading, choose this new page as your "Posts page"

Now when you click the link to this page in your menu, it should list all your recent posts (no messing with code required).

like image 27
Simon East Avatar answered Oct 12 '22 01:10

Simon East