Recent Topics

1 Jan 26, 2010 05:30    

My b2evolution Version: Not Entered

My b2evolution Version:3.3 Not Entered

Hi everybody,

I'm dying to find a way to paginate comments. I've found this one, but I just can't get it to work. Could anybody help me of check what's wrong ?

thnx in advance!

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).

PHP:

	$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
noteInformation: Your skin's _feedback.php file may simply require a file, of the same name, from the directory above (i.e., /skins/_feedback.php).

If this is the case, you have a choice. If you want paged comments for EVERY skin that's set up similarly ... then modify /skins/_feedback.php. If you only want paged comments for a SPECIFIC skin, then copy the code from /skins/_feedback.php into that specific skin's _feedback.php file (i.e., /skins/[yourSpecificSkin]/_feedback.php), replacing (or commenting out) the require statement.

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>//</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:


	<?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', 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>';

	 // ------------------------------- end paged comment workhorse ---------------- 

	?>


ideaIdea: One can indicate how many pages of comments there are (and what page is being viewed) by inserting the following code around the <h4> comment page "title" (basically, wherever you want - so experiment ... just remember that the code is PHP and should be INSIDE "<?php" and "?>" tags).

PHP:

$comment_pages=ceil($comment_max/$max_comments);

	if ( $comment_max > $max_comments ) 

	{ 

	  echo '&nbsp;<small>(Page '.($comment_page+1).' of '.($comment_pages).')</small><br />' ; 

	}

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:

// -------------------- paged comment controls ----------------------------- 

	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>';  

	            }

	        }

	    } 

	// --------------------- 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)
alert** WARNING ** This next step is a core hack

Up to now, everything has been a "skin modification". This means that when you upgrade your b2evolution installation, the upgrade won't overwrite these modifications.

This next step is a core hack, meaning that it WILL be overwritten when upgrading to a new version. When doing a core hack, it's best to make a backup of the original core file and keep track of which core files have been modified, so that you don't lose these hacks when upgrading to a newer version.

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:

PHP:

<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.

PHP:

<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>


Form is loading...