The Comments add-on will load and display blog comments using the core Ajax Load More infinite scroll functionality.

Improve website performance, decrease load times and reduce stress on your server by lazy loading blog comments when requested by your users – view example.

Features

A few key features of the Comments add-on for Ajax Load More.

Boost Performance

Reduce queries on initial page load by loading comments only when requested by visitors.

View Example

WooCommece Reviews

Display native WooCommerce product reviews in an infinite scroll or load more listing.

View Example

Theme Integration

Maintain the current comments look and feel by using the comment styling from your theme.

Add-on Details

Learn more about the Comments add-on.

How It Works

The Comments add-on works by querying individual posts for user comments or reviews. Each comment and replies are returned using the familiar Ajax Load More infinite scroll / lazy load functionality.

By using a unique comment query, existing Ajax Load More functionality, and core WordPress functions such as wp_list_comments, the Comments add-on can return post comments or WooCommerce reviews in an intuitive and user-friendly format while helping improve the overall performance and user experience of your website.

Pro-Tip: You can also lazy load Comments using the Paging add-on – View Example.


Examples


Shortcode Parameters

The following shortcode parameters are available with the Comments add-on.

commentsEnable Ajax Load More to display blog comments. Default = ‘false’
comments_post_idThe ID of the current single post. Default = ‘get_the_ID()’
comments_per_pageThe number of top level items to show for each page of comments. Default = ‘5’
comments_typeThe type of comment(s) to display. Default = ‘comment’
comments_styleSelect the HTML container style for your comments. Default = ‘ol’
comments_templateSelect a repeater template that will display comment data. Default = null
comments_callbackA custom callback function that will display each comment. Default = null

Shortcode Builder

The following screenshot illustrates the process of building a Comments shortcode using the Ajax Load More shortcode builder.

Comments Shortcode Builder Options

Example Shortcode

[ajax_load_more comments="true" comments_post_id="'.get_the_ID().'" comments_callback="my_theme_comments" pause="true" button_label="Load Comments"]

Implementation

Implementing comments with Ajax Load More is a two-step process and will require modification of your single post template.

Step 1 – Select Comment Template or Callback Function

The first step will be to determine how you want Ajax Load More to display your comments – with the Comments add-on you can either select an existing callback function (from your theme) or create your own repeater template to handle the markup/display of your comments.

Comment Template

Creating your custom template for displaying WordPress comments is a straightforward and intuitive process and is a lot like building a standard Repeater Template for Ajax Load More.

Construct a repeater template using HTML and standard WordPress comment functions such as comment_date() and comment_author() then select this template when building out a comment shortcode.

comment-repeater

When building a custom comment template you should never close the opening HTML element – the closing </ li> is purposely left out of the template and will be closed by WordPress – View Gist

Callback Function

A comment callback is a function that is available from within a theme and is used to render and display each comment. When you enter a callback function name into the comments_callback shortcode parameter, Ajax Load More will attempt to render comments using this function.

The majority of premium and custom themes have callbacks for displaying comments. Please see comments.php or functions.php within your theme directory to locate the callback function for your theme – see the example below.

<?php
 // comment.php
 // An example of where to find your the name of your themes callback function.
?>
<ol class="commentlist">
  <?php wp_list_comments( array( 'type' => 'comment', 'callback' => 'my_comment_callback' ) ); ?>
</ol>
PHP

Step 2 –  Adding Shortcode to Template

Locate your existing comments_template() function and replace it with an Ajax Load More comments shortcode and other comment related functions as seen in the code sample below.

<?php
/**
 * WordPress single template (single.php).
 * Displaying comments using Ajax Load More
 * 
 * @see https://connekthq.com/plugins/ajax-load-more/add-ons/comments/
 */
?>
<div class="post-container">
<?php while (have_posts() ) : the_post(); ?>
  <article id="post-123">
    <div class="post-content">
      <?php 
        the_title( '<h1>', '</h1>');
        the_content(); ?>
    </div>
    <?php if(comments_open()) : ?>
    <footer id="comments">
      <?php 
      // comments_template(); // Removed in favor of Ajax Load More.
      $comment_count = get_comment_count($post->ID);
      if ( $comment_count['approved'] > 0 ) :
        echo '<h2 class="comments-title">Comments (' . $comment_count["approved"] . ')</h2>';
        echo do_shortcode( '[ajax_load_more comments="true" comments_post_id="' . get_the_ID() . '" comments_per_page="4" comments_style="ol" comments_template="default" button_label="Load Comments"]');
      endif;
      comment_form(); // Standard WP Comment form.
    ?>
    </footer>
    <?php endif; ?>
  </article>
<?php endwhile; ?>
</div>
PHP

In most cases, you will be directly editing single.php but depending on your theme you may need to edit another file – e.g. index.php.


Installation

Upon purchase of this add-on you will receive a confirmation/purchase receipt email. Your receipt will contain a direct link for downloading your copy of Ajax Load More: Comments and a license key.

After downloading the add-on, upload the unzipped files to your /wp-content/plugins/ directory or visit your plugins dashboard and upload the downloaded .zip under Add New.

License Activation

To activate your add-on and receive updates directly in your WordPress plugins dashboard users are required to enter the license key that was included with their purchase receipt.

To activate a license key:

  1. Visit the Licenses section within the Ajax Load More plugin.
  2. Enter the product key and click Activate License.
  3. If the status indicator turns green your add-on has been successfully activated (example below).
License Key Example

If you did not receive a confirmation email containing your license key, please check your spam/junk folder. If you still cannot locate the email, contact me at darren [at] connekthq.com or use the Product Support form.