Skip to content

Instantly share code, notes, and snippets.

@gregrickaby
Last active November 26, 2018 01:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gregrickaby/6115852 to your computer and use it in GitHub Desktop.
Save gregrickaby/6115852 to your computer and use it in GitHub Desktop.
Display all posts in a page template
<?php
/**
* Template Name: All Posts
*
* This template lists all posts via WP_Query and get_posts();
*/
get_header();
// WP_Query arguments
$args = array (
'posts_per_page' => '-1',
'ignore_sticky_posts' => true,
'order' => 'DESC',
'orderby' => 'date',
'cache_results' => true
);
// Hook into WP_Query and pass default arguments
getposts = get_posts( $args );
// Loop through each post
foreach( $getposts as $post ) : ?>
<h1><?php the_title(); ?></h1>
<?php the_excerpt(); ?>
<?php endforeach;
get_sidebar();
get_footer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment