Load more posts via Ajax WordPress

I am using load more with ajax for my portfolios and it’s working well but I’m having a problem when I am making the portfolio as a front page, the load more isn’t working anymore, it displays same posts

This is the code of load more in js

Read More
var isoElem = jQuery('.masonry-images');
if(isoElem.length > 0) {

    var elem = isoElem[0];
    var iso = new Isotope( elem, {
      itemSelector: '.work-image',
    });
}

var page = 1;
 var loadMorePosts = jQuery('#load-more-posts').text();

  function loadMore() {
    page++;
    jQuery.ajax({
        type: "GET",
        url: './page/' + page,
        beforeSend: function () {
            jQuery('#load-more-posts').html("<i class='fa fa-spinner fa-spin'></i>");
        },
        complete: function () {

        },
        success: function (data) {
            var $data = jQuery(data).find('.single-blog,.work-image');
            if ($data.length > 0) {
                jQuery('#load-more-posts').html(loadMorePosts);
              jQuery('#blog-posts,#portfolio-posts').append($data);

              if(isoElem.length > 0) {
                iso.appended($data);
              }

              $data.css("display", "none");
              $data.fadeIn("slow");
            }
            else {
              jQuery('#load-more-posts').html('No More Posts');
            }
        },
        error: function () {
            jQuery('#load-more-posts').html('No More Posts');
        }

    });
}

jQuery('#load-more-posts').click(function(e) {
    e.preventDefault();
    loadMore();
});

You can try here live at ‘ http://illyrianthemes.com/themes/vicenza/ ‘ here is not working when I remove as front page of WordPress then works perfectly for example check four columns ‘ http://illyrianthemes.com/themes/vicenza/four-columns/ ‘.

Best Regards

Related posts

1 comment

  1. After a long research I found the answer if someone needs it.

    Instead of doing this:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts( array( 'post_type' => 'post', 'paged' => $paged ) );
    

    do this:

    if ( get_query_var('paged') ) {
    
    $paged = get_query_var('paged');
    
    } elseif ( get_query_var('page') ) {
    
    $paged = get_query_var('page');
    
    } else {
    
    $paged = 1;
    
     }
    
    query_posts( array( 'post_type' => 'post', 'paged' => $paged ) );
    

    Maybe it will help someone.

Comments are closed.