Skip to content

Instantly share code, notes, and snippets.

@CEscorcio
Created August 1, 2013 13:48
Show Gist options
  • Save CEscorcio/6131511 to your computer and use it in GitHub Desktop.
Save CEscorcio/6131511 to your computer and use it in GitHub Desktop.
How to add navigation to a blog
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; // setup pagination
$the_query = new WP_Query( array(
'post_type' => 'clients',
'paged' => $paged,
'posts_per_page' => 5)
);
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<div>' . get_the_title() . '</div>';
the_content();
endwhile;
echo '<nav>';
echo '<div>'.get_next_posts_link('Older', $the_query->max_num_pages).'</div>'; //Older Link using max_num_pages
echo '<div>'.get_previous_posts_link('Newer', $the_query->max_num_pages).'</div>'; //Newer Link using max_num_pages
echo "</nav>";
wp_reset_postdata(); // Rest Data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment