Recent Topics

1 Dec 06, 2014 18:06    

Version 5.1.2
Hi

I would like to know the variable, if there is one, for the comment count; that being the number of comments not the number of times it has been viewed.

I would also like to have the pagination in reverse order when the comments are chronologically reverse.

What I am trying to do is to show only one comment, (done) and have it numbered, for example as, 6 of 14.

Thanks

2 06 Dec 2014 20:58

OK I partly have what i want.
Two options are:
in /skins/my**skin/_item_feedback.inc.php
a) add echo "<em> Most Recent First</em>";


if( $params['disp_section_title'] )
		{	// Display title
			echo $params['before_section_title'];
			echo implode( ', ', $disp_title);
echo "<em> Most Recent First</em>";
			echo $params['after_section_title'];
		}

This just informs that the comments are in reverse order

b) around line 244 add
echo "<div class='center'>Page " . $CommentList->page . " of " . implode( ', ', $disp_title) . ": <em>Most Recent First</em></div>";

This gives (p of pages)

3 06 Dec 2014 22:07

around line 260- you will find;

		$comment_number = ( ( $CommentList->page - 1 ) * $CommentList->limit ) + 1;

Add these two lines between that and while loop:

$comment_count = $CommentList->total_rows;
echo "<div class='center'>Page " . $comment_number . " of " . $comment_count . ": <em>Most Recent First</em></div>"; 

So that it will finally look like:

// Set number of comment depending on current page
		$comment_number = ( ( $CommentList->page - 1 ) * $CommentList->limit ) + 1;
		$comment_count = $CommentList->total_rows;
		 echo "<div class='center'>Page " . $comment_number . " of " . $comment_count . ": <em>Most Recent First</em></div>"; 

		/**
		 * @var Comment
		 */
		while( $Comment = & $CommentList->get_next() )
		{	// Loop through comments:

4 06 Dec 2014 22:57

Thanks tilqicom

so what I was looking for in part was
$CommentList->total_rows
where could I have found such info?

any idea on how to reverse the page numbers ? in
$CommentList->page_links( array())

5 07 Dec 2014 00:07

I usually var_dump($stuff) to find out stuff to see if i can get my hands on anything useful, in this case I did var_dump($CommentList), did a quick ctrl+f for "11" since my post had 11 comments and found out that the number was stored there.

Just var_dump($things) be that a variable, class, function etc to see what it outputs to give you pointers.

Apart from that, I usually do a search in whole /b2evolution directory in my local folder to find a particular function. For example in this case, I searched for "function page_links(" and there was 3 file results, 2 were post related 1 was comments related.
I found the function at b512\inc\comments\model\_commentlist.class.php near line 650.

However, as you can see below, unfortunately there is no paramater to reverse the links order. Something maybe done to manually generate the reverse navigation.

function page_links( $params = array() )
	{
		$default_params = array(
				'block_start' => '<p class="center">',
				'block_end' => '</p>',
				'block_single' => '',
				'links_format' => '#',
				'page_url' => '', // All generated links will refer to the current page
				'prev_text' => '&lt;&lt;',
				'next_text' => '&gt;&gt;',
				'no_prev_text' => '',
				'no_next_text' => '',
				'list_prev_text' => '...',
				'list_next_text' => '...',
				'list_span' => 11,
				'scroll_list_range' => 5,
			);

		// Use defaults + overrides:
		$params = array_merge( $default_params, $params );

		if( $this->total_pages <= 1 || $this->page > $this->total_pages )
		{	// Single page:
			echo $params['block_single'];
			return;
		}

		if( $params['links_format'] == '#' )
		{
			$params['links_format'] = '$prev$ $first$ $list_prev$ $list$ $list_next$ $last$ $next$';
		}

		if( !is_null( $this->Blog ) && $this->Blog->get_setting( 'paged_nofollowto' ) )
		{	// We prefer robots not to follow to pages:
			$this->nofollow_pagenav = true;
		}

		echo $params['block_start'];
		echo $this->replace_vars( $params['links_format'], $params );
		echo $params['block_end'];
	}

6 07 Dec 2014 01:25

Although, I created a custom block if you want to build it manually:

 //Start reverse nav
 $reverse_nav = '';
 $curr_p = $_GET['c_paged'];
 //Insert before params
 $reverse_nav .= $params['nav_block_start'];
 // prev link	
 $r_prev_link = '<a rel="prev" href="' . url_add_tail( $Item->get_permanent_url(), '?c=1&redir=no&c_paged='.($curr_p + 1).'#comments' ) . '">' . $params['nav_prev_text'] . '</a>';
if($r_curr_p != 1) $reverse_nav .= $r_prev_link;
 // iterate through comments
for($comm_i = 1; $comm_i <= $comment_count; $comm_i++){	
	if($comment_count - $curr_p + 1 == $comm_i) {
		$reverse_nav .= '&nbsp;<strong class="current_page rrr">'.$comm_i.'</strong>';
	}
	else {
		$reverse_nav .= '&nbsp;<a href="' . url_add_tail( $Item->get_permanent_url(), '?c=1&redir=no&c_paged='.( $comment_count - $comm_i + 1).'#comments' ) . '">' . $comm_i . '</a>';
	}
	url_add_tail( $Item->get_permanent_url(), '?c=1&redir=no&c_paged='.($comment_number - 1).'#comments' );
	if($comm_i==$comment_count) break;
}
 // next link		
 $r_next_link = '<a rel="next" href="' . url_add_tail( $Item->get_permanent_url(), '?c=1&redir=no&c_paged='.($curr_p -1).'#comments' ) . '">' . $params['nav_next_text'] . '</a>';
 if($r_curr_p != $comment_count) $reverse_nav .= $r_next_link;
//Insert before params
 $reverse_nav .= $params['nav_block_start']; 
// output the reverse nav
 echo $reverse_nav;
//End reverse nav

7 07 Dec 2014 11:35

Thanks

Will report later

Looks like we're done here :)


Form is loading...