Loading whole pages with ajax in wordpress

时间:2016-07-28 20:26:52

标签: javascript jquery ajax wordpress

Im having a problem loading pages in wordpress with ajax. I have to make animated page transition, so i decided to use ajax and put page content into a div which i will animate into view. I created this logic, that works 50% of the time. There are generally a lot of weird bugs.

So my question did anyone create ajax page loader in wordpress? I read a bit about using ajax with wordpress, and that i had to use wordpress built in features, but I didn't get why is that. Also I don't know how to get the back button to work properly.

$( links ).click(function(e) {

    var link = $(this).get(0).href;
    $('body').append('<div class="contain-all"></div>');

    $('.contain-all').load(link);

    if(link!=window.location){
      window.history.pushState({path: link},'',link);
    }

    e.preventDefault();
});

Hope somebody has the anserws I need. :)

1 个答案:

答案 0 :(得分:1)

好的,我在wordpress和加载页面上阅读了一些关于ajax的内容,你可以通过创建模板部分来实现这一点,你将通过wordpress functions.php中的函数来获取,通过使用ajax调用它。这听起来很复杂,(部分原因是这样),但你可以在这里阅读更多相关内容:

https://premium.wpmudev.org/blog/load-posts-ajax/

如果有人有疑问他们可以在这里问他们,所以每个人都可以访问它们。