AJAX在Wordpress中加载了帖子

时间:2018-03-21 22:00:18

标签: jquery ajax wordpress

我试图在我的Wordpress网站上发布AJAX加载帖子: http://wordpress.krakowski.website

在我的基本网站上,AJAX帖子正在运行:http://wordpress.krakowski.website

(博客部分)。

我的JS代码:

    $('.post__link').click(function (e) {
  $('.post-content').animate({ scrollTop: 0 }, "slow");

  var url = $(this).attr('href');
  $('.post-content').load(url + ' #content', function(responseTxt, statusTxt, jqXHR){
    if(statusTxt == "success"){
      $('.post-content').addClass('post-content__visibility');
      $('.menu-btn').toggleClass('btn-visability');

      var postHeader = $('.post-header').offset().top;

      $(window).scroll(function () {
        var postContentTop = $('.post-content').scrollTop();
        var contentText = $('.content-text').scrollTop();

        if (postContentTop > postHeader && postContentTop < contentText) {
          $('.menu-btn').removeClass('menu-btn__dark');
        } else {
          $('.menu-btn').addClass('menu-btn__dark');
        }
      })


      if ($('.post-content').hasClass('post-content__visibility')) {
        $('.menu-btn').click(function () {
          $('.post-content').removeClass('post-content__visibility');
          $('.label-menu-popup').text('Menu').fadeIn();

        })
        $('.label-menu-popup').text('Powrót na główną');
      } else {
        $('.label-menu-popup').text('Menu');
      }
  } else {
    window.location.href=url;
  }
  })
  e.preventDefault();
});

0 个答案:

没有答案