Skip to content

Instantly share code, notes, and snippets.

@geoffyuen
Created November 6, 2013 20:06
Show Gist options
  • Save geoffyuen/7343212 to your computer and use it in GitHub Desktop.
Save geoffyuen/7343212 to your computer and use it in GitHub Desktop.
WP minimal loop with pagination - yuck
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$the_query = new WP_Query(
array(
'posts_per_page' => '5',
'paged' => $paged
)
);
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<h3>';
the_title('<a href="' . get_the_excerpt() . '" target="_blank">', '</a>');
echo '</h3>';
foreach((get_the_category()) as $category) {
echo $category->cat_name . ' ';
}
endwhile;
echo '<hr>';
next_posts_link( '< older ', $the_query->max_num_pages );
previous_posts_link( ' newer > ' );
wp_reset_postdata();
else:
_e( 'Sorry, no posts matched your criteria.' );
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment