WordPress Pagination Front Page

adding-pagination

In this tutorial I will show you how to add a Pagination to your static front page of your wordpress website. I wrote this code while I was re-working my portfolio section of my own website, so once I got it to work, I thought I share it with everyone.

Your pagination has to go inside your custom query, so lets first take a look at a custom query.

Make sure you set your $args parameters for your own needs.

Now lets add in our Pagination to the custom query. The first thing is to add in this snip (‘paged’ => $paged) to the $args array to the custom query from above.

Next we add this ($paged = ( get_query_var( ‘page’ ) ) ? get_query_var( ‘page’ ) : 1;) above the $args array.

Now this line here is the reason for the Pagination to work on a Static Front Page of your WordPress website.

Where it indicates ‘page’ is the cause of all this really. If you want to use this on an actual custom page template with its own custom query, you need to change ‘page’ to ‘paged’.

This is all documented here on this page https://codex.wordpress.org/Function_Reference/get_next_posts_link in the section of ‘Usage when querying the loop with WP_Query‘.

Next we add in the code for our numbered pages to show up along with Next and Previews links. This will be placed between the “end while” and “end if” closing of the custom query.

There you have it folks! The best and easiest way of adding a Pagination to your Static Front Page of your WordPress website. The pagination when added to your template will show up at the bottom of your content being queried. If you wish to have the Pagination show up at the top of your content, just copy the div id=”My-Pagination” portion and add it in between the start of the IF statement and the start of the WHILE statement.

HERE IS THE FULL CODE