Load WordPress Post Content into DIV with Ajax and jQuery

I was recently playing around with a WP website where I wanted to show post content into a specific div element when a link (the post title in my case) is clicked, without having to refresh the page or going to an inner page. In order to do this, we have to use Ajax and jQuery. Here’s how you can achieve this neat effect step by step:

Step 1: Use the following code where you want to display the post titles:

Step 2: Add the div container where the post content will load:

You can put it anywhere in your website.

Step 3: Edit the single.php template

It’s a really simplified version of the single post template. You can go ahead and customize it.

Step 4: Adding some jQuery code

Copy and paste the snippet into your page (where the post content is loading), preferably above the closing </body> tag. Make sure you have jQuery loaded as well.

That’s it! If you find it a bit confusing and have some questions or need help, don’t hesitate to contact me.

5 سال پیش

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

این سایت از اکیسمت برای کاهش هرزنامه استفاده می کند. بیاموزید که چگونه اطلاعات دیدگاه های شما پردازش می‌شوند.