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:
- Choosing and inserting $max_comments & $comment_order variables.
- Inserting the part that does the work into your skin's _feedback.php file.
- Deciding how many and where you want to place the page control code in _feedback.php.
- (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:
- $max_comments - The number of comments you want per page.
- $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).
PHP:
| $max_comments = 10; |
| $comment_order = 'desc'; |
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):
PHP:
| <span style="color:orange"><strong> |
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:
| <?php |
| if ( isset( $max_comments ) ) |
| { |
| $comment_max = $DB->get_var( 'select count(*) from T_comments where comment_post_ID = '.$Item->ID ); |
| param( 'comment_page', 'integer', 0, true ); |
| $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 CommentList( 0, implode(',', $type_list), array(), $id, '', $comment_order, '', $comment_limit ); |
| } |
| else |
| { |
| $CommentList = & new CommentList( 0, implode(',', $type_list), array(), $id, '', 'ASC' ); |
| } |
| echo '<a id="CommentTop"></a>'; |
| |
| ?> |
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.
PHP:
|
|
| if ( isset( $max_comments ) ) |
| { |
| if ( $comment_page > 0 ) |
| { |
| 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 + 1 )< ( $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>'; |
| } |
| } |
| } |
|
|
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.
- Near the top of the function, just under the "global" definition (in gray below), add a global statement for the variable $comment_page:
PHP:
| <span style="color:#aaa">global $Plugins, $Hit, $more, $preview;</span> |
| <span style="background-color:#cfc">global $comment_page; |
- 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.
PHP:
| <span style="color:#aaa"> |
|
|
| </span> |
| <span style="color:#aaa"> |
|
|
| <span style="background-color:#cfc"> |
| <span style="background-color:#cfc">if( $dispmore && !$preview && $Hit->is_new_view() && $Hit->agent_type != 'robot' && !$comment_page ) |
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 ...
*****************************************************************************************************************************
Recent comments