Paged comments

7th Feb 2006 ¥åßßå

Installation Instructions for Paged Comments

Installation involves four steps. Most are to your skin's _feedback.php file, but depending on what you want to do, your index.php or stub file and /evocore/_item.class.php files might be involved. The four steps are:

  1. Choosing and inserting $max_comments & $comment_order variables.
  2. Inserting the part that does the work into your skin's _feedback.php file.
  3. Deciding how many and where you want to place the page control code in _feedback.php.
  4. (If needed) - Making sure scanning paged comments doesn't increment your "view" count.

Step 1: Set Your Variables

There are two variables used with paged comments:

  1. $max_comments - The number of comments you want per page.
  2. $comment_order - Oldest-to-Newest or visa versa.

WHERE you define these variables will depend largely on what your b2evolution setup is like and how you want paged comments to work. For each blog you want to have paged comments, you can put the variables into the index.php or stub file for those blogs. If you use one skin per blog (don't allow skin switching), then you can add the variables (with similar or different settings) to the each skin's _feedback.php file. It can either be a per-skin thing, or a per-blog thing. The choice is yours.

Add the following variables to (a) the blog's index.php file or stub.php file -or (b) a skin's _feedback.php file. Where in the file isn't terribly important, but it's convention to place it near the top somewhere (just make certain that they're with other PHP code, inside "<?php" and "?>" tags, (or adding them if needed).


$max_comments 10// number of comments to display per page
$comment_order 'desc'// Oldest or Newest comments first

Step 2: Insert the Paging Work Horse

This code is the meat of the paged comments modification. It goes into your skin's _feedback.php file, which should be in the /skins/[YourSkinName] folder. It will replace a line of existing code, so the first step will be to find and comment out (or delete) the following line (add the two forward slashes to comment the line out, as shown in orange, below):


<span style="color:orange"><strong>//</strong></span> $CommentList = & new CommentList( 0, implode(',', $type_list), array(), $id, '', 'ASC' );

Next, insert the code below. You can actually REPLACE the line above if you wish, but we recommend placing it a tad higher up in the file, just ABOVE the <h4> "Title" lines, which should be only a few lines up from the $CommentList line you just commented out. (You may or may not need the starting "<?php" and ending "?>" PHP tags, depending on where you insert the code (just make certain that the PHP code is correctly wrapped).


<?php // -------------------------- start paged comment workhorse  ---------------------
  if ( isset( $max_comments ) ) 
        $comment_max $DB->get_var'select count(*) from T_comments where comment_post_ID = '.$Item->ID ); 
        param'comment_page''integer'0true ); 
        $comment_limit $comment_page $max_comments
        if ( !isset( $comment_order ) ) $comment_order 'asc'
        $comment_limit = ( ( !$comment_limit ) ? $max_comments $comment_limit.','.$max_comments ); 
        $CommentList = & new CommentList0implode(','$type_list), array(), $id''$comment_order''$comment_limit ); 
        $CommentList = & new CommentList0implode(','$type_list), array(), $id'''ASC' ); 
echo '<a id="CommentTop"></a>';
 // ------------------------------- end paged comment workhorse ---------------- 

Step 3: Insert the Page Control

Again, you have options regarding the placement of the code that adds page control. You might like to have controls placed at the top of your comments and then again at the bottom. If so, then you'll need to insert the code below, twice. If you only want it at the top or bottom, then you'll only need to insert it once.

  • Top controls: Insert the code just below the "echo <h4>" comment page title. It should be only a few lines below the code chunk you added in step 2.
  • Bottom controls: Insert the code just below the commented section that demarks "End of a Comment/TB/PB", which is close to the bottom of the file.

Whichever location you choose, make certain that the code is properly contained inside PHP tags.


// -------------------- paged comment controls ----------------------------- 
if ( isset( $max_comments ) ) 
      if ( $comment_page 
          echo '<div class="pgdCmnts"><a href="'.regenerate_url'comment_page''comment_page='.( $comment_page 1) ).'#CommentTop">'.( ( $comment_order == 'desc' ) ? 'Newer' 'Older' ).' Comments</a> ';
    } else { 
        if( $comment_max $max_comments 
              echo '<div class="pgdCmnts"><span>'.( ( $comment_order == 'desc' ) ? 'Newest' 'Oldest' ).' Comments</span>'
      if ( ( $comment_page )< ( $comment_max $max_comments ) ) 
          echo ' <a href="'.regenerate_url'comment_page''comment_page='.( $comment_page 1) ).'#CommentTop">'.( ( $comment_order == 'desc' ) ? 'Older' 'Newer' ).' Comments</a></div>'
    } else { 
          if( $comment_max $max_comments 
              echo '<span> '.( ( $comment_order == 'desc' ) ? 'Oldest' 'Newest' ).' Comments</span></div>';  
// --------------------- end paged comment controls ----------------------------

That's it. You should now have paged comments. However, if you use "views", you'll want to go on to step 4.

Step 4: Fixing the View Count (core hack)

Each navigational click through paged comments, either to a "newer" page or an "older" page, will increment the view count for the post. If you utilize or display the view count, this may not be a behavior you want, because comment paging will artificially inflate the view count for a post.

The fix for this is easy, but it currently requires an edit to the /evocore/_item.class.php file. Make a backup of the original file and then edit a copy, searching for the 'content' function (around line 790). You'll need to make two changes, both very easy and highlighted below.

  1. Near the top of the function, just under the "global" definition (in gray below), add a global statement for the variable $comment_page:


    <span style="color:#aaa">global $Plugins$Hit$more$preview;</span>
          <span style="background-color:#cfc">global $comment_page;          // (pgd comments)</span>

  2. Further down in the same function, look for the following gray code. You'll want to comment out the if statement, which is the last gray line, by adding the two slashes in front of it. Then add the new line below it.


    <span style="color:#aaa">/*</span>
         <span style="color:#aaa">* Check if we want to increment view count, see {@link Hit::is_new_view()}</span>
         <span style="color:#aaa">*/</span>
        <span style="color:#aaa">#pre_dump( 'incViews', $dispmore, !$preview, $Hit->is_new_view() );</span>
        <span style="background-color:#cfc">//</span> <span style="color:#aaa">if( $dispmore && !$preview && $Hit->is_new_view() && $Hit->agent_type != 'robot' )</span>                 <span style="background-color:#cfc">// (pgd comments)</span>
        <span style="background-color:#cfc">if( $dispmore && !$preview && $Hit->is_new_view() && $Hit->agent_type != 'robot' && !$comment_page )  // (pgd comments)</span>

NOW, your paged comments are complete. All that's left is to style the controls. If you're a pro, you can probably take it from here, but for suggested styling instructions and CSS, read on ...

  1. Introduction
  2. Installation instructions
  3. CSS Styling of Page Controls
  4. FAQs & Enhancements


Comment from: dub27
Hi, using b2evolution 1.9.2

all going well until adapting the hit counter. For some reason, b2evolution does not like the [bg= code

error message:
Parse error: parse error, unexpected '[' in C:\Documents and Settings\HP_Administrator\My Documents\websites\b2evolution\blogs\inc\MODEL\items\_item.class.php on line 1134

should the [bg be in quotes? or is the code deprecated?


27/02/07 @ 15:15
Comment from: dub27
fyi 1.9.2

database plus_comments table has become "comments"

So instructions above for select from "from evo_plus_comments where"

need to be adapted to new table
27/02/07 @ 15:39
Comment from: dub27
Hi again,

I couldn't get this up and running, unfortunately with 1.9.2. Perhaps the mechanics have changed in relation to finding comments counts, or such. If you have an update for 1.9.2 will you let me know?

Thanks for your plugins/hacks!

27/02/07 @ 16:12
Hi Dub27,

The [bg= stuff is actually meant to be a background colour, but the bbcode renderer appears to have forgotten how to handle it :S

The table name is another error, it was the prefix of the tables in my db at the time, it really should read T_comments ( I've amended the name in the post, thanks for catching that ).

I've not actually tried this hack in my 1.9.2 install, when I get a free moment I'll give it a whirl and see if I can make it work.

27/02/07 @ 16:28
Comment from: dub27

I gave it another try, but not sure what the glitch is -- There are no error messages but there is no control mechanism in the comments panel and comments are not responding to the restriction ie 4 comments.

Any ideas?

Another idea you that might appeal to you in relation to this hack is this link --

it creates checkboxes for deleting multiple posts (I couldn't get it to work however, but really like the concept)

27/02/07 @ 23:51

Comments are closed for this post.