Carlo Fontanos

Full Stack Developer

Simple Posts Pagination in WordPress

If ypu have been following my WordPress Tutorials, I made two posts where I discussed how you can setup a pagination that loads the data from the server using AJAX. In this tutorial we are going to focus on creating a very simple pagination without AJAX and by just relying on PHP and WordPress functions. So let’s get started!

This simple pagination includes buttons for “Next”, “Prev”, “First”, and “Last”. You can also configure how many number bullets to show on screen.

// Sanitize the received page $page= sanitize_text_field($page_number);$cur_page=$page;$page-=1;// Set the number of results to display$per_page=5;$previous_btn=true;$next_btn=true;$first_btn=true;$last_btn=true;$start=$page*$per_page;

// Set the table where we will be querying data$table_name=$wpdb->prefix.'posts';