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
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() ) : ?>
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( '← Older posts', $wp_query ->max_num_pages); ?> <?php previous_posts_link( 'Newer posts →' ); ?>
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:
Now when you click the link to this page in your menu, it should list all your recent posts (no messing with code required).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With