Support » Plugin: Comments - wpDiscuz » Fix reqd. for updating total no. of comments when loading via ajax

  • Resolved biswajeet

    (@biswajeet)


    Hi, it is very much useful when loading comments via ajax in caching environment. But it is also necessary to update the total number of comments in that section because cached page always shows the old number of comments and we need to clear the cache in order to shows the actual number.

    thanks…
    biswa!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support gVectors Support

    (@gvectorssupport)

    Hi,

    Please let us know the cache system you’re using.

    Thread Starter biswajeet

    (@biswajeet)

    Hi, we are using a custom caching implementation.

    In your code in the comment section:

    <div class="wpd-thread-info " data-comments-count="yy"> <span class="wpdtc" title="yy">yy</span> Comments</div>

    You can fix the issue by simply updating the total nos. of comments for the element span.wpdtc replacing the old number yy after ajax loading is completed.

    Alternately, if you provide api option for javascript callback(args…) post ajax loading then we can also hook our code to accomplish the task.

    thanks,
    biswa!

    Plugin Support gVectors Support

    (@gvectorssupport)

    Hi,

    You can fix the issue by simply updating the total nos. of comments for the element span.wpdtc replacing the old number yy after ajax loading is completed.

    Currently wpDiscuz works exactly in this way. I.e. it replaces the old number after ajax loading. It seems that the caching system you’re using doesn’t update the comment count.

    Thread Starter biswajeet

    (@biswajeet)

    Hi I am currently using the latest version – 7.2.2 and total comments number is not updating. We can check if it actually does by the following test code running early as the DOM ready –

    $('.wpd-thread-info > span.wpdtc').text('...');

    It will remove the total comments no. and watch to see if the post ajax comments loading also update the number.

    Since it’s not working for me, I have to write the following codes in my script file within my themes to make it work –

    
    // Options for the observer
    const config = { attributes: false, childList: true, subtree: true },
            
    commentNode = document.querySelector('#wpd-threads > .wpd-thread-list'),
    
    // Create an observer instance
    observer = new MutationObserver(function(mutationsList, observer) {
    
      //observe only once
      this.disconnect();
    
      setTimeout(() => {
    
        let comments = $('.wpd-thread-list .wpd-comment-author').length;
    
        $('.wpd-thread-list .wpd-view-replies').each((i, replyComment) => {
    
          const r = $(replyComment).text().match(/\d/);
    
          if ( r.length ) 
            comments += parseInt(r[0]);
    
        });
    
        $('.wpd-thread-info').attr('data-comments-count', comments)
          .find('> span.wpdtc').attr('title', comments).text(comments);
                
      }, 1000);
    
    });
    
            
    // Start observing the comment node when available
    if ( commentNode ) {
                
      $('.wpd-thread-info > span.wpdtc').text('...');
      observer.observe(commentNode, config);
                
    }
    

    I hope this will help out anyone looking for the same issue…

    thanks,
    biswa!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.