How to load Wordpress Post with Ajax onclick

前端 未结 3 1194
名媛妹妹
名媛妹妹 2020-12-09 00:38

I have spent hours reading and trying tutorials. I cant seem to find a solution that works and I know it should be pretty easy but I struggle with AJAX. :(

I want to

3条回答
  •  爱一瞬间的悲伤
    2020-12-09 01:10

    Ok, I think I have solved this after a long process of trial and error.

    This seems to work, but please let me know if it is not the correct way of doing this

    Javascript:

    jQuery.noConflict();
    jQuery(document).ready(function($){
        $.ajaxSetup({cache:false});
        $("a.ajax").click(function(){
            var post_url = $(this).attr("href");
            var post_id = $(this).attr("rel");
            $("#tabs").html('
    loading...
    '); $("#tabs").load(post_url); return false; }); });

    The page where I want to display the post content (I am using custom post types called "artwork":

    And the single post "single-artwork.php". Note: Dont use get_header or get_footer etc:

    
      

    Thanks!

提交回复
热议问题