WordPress ajax next previous button without plugin

Create an index.html file :

Include jQuery and respective css file in thesection of your html template.

Explicit javascript code :

In the above javascript code, we are loading the initial contents(10 posts) first using loadCurrentPage() function. Then once the prev or next button is clicked, we increment the offset number by 10 (for getting next 10 posts). The contents are retrieved from serverside posts.php. Below is the prev and navigation buttons.

Below is the div in which you load your contents.

Create a posts.php file :

 

Every time next button is pressed, you increment the offset by 10 and send as an argument to posts.php. In the posts.php, use this offset and get the next 10 posts and list. See the below live demo and you can download the script to try yourself. For the download to work, you need to put posts.php script into your PHP server and proper path for WordPress need to be included in that file.

add a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*