Recent Topics

comments_number() function update

Started by on Oct 08, 2003 – Contents updated: Oct 08, 2003

Oct 08, 2003 20:33    

Howdy all,

I'm just getting started with b2evo and I've come across something that I think could be updated. The comments_number() function defaults to using three different texts to describe there are are any comments. I want to display one message like this: "Display Comments / Leave a Comment (#)" regardless of how many comments are to be displayed. Am I the only one that wants to use this function this way or is there another function I should be using?

Below is the updated function code for anyone who's interested in it:

//////
//	UPDATED: 03.10.08 - Changed comments_number() function to use one 
//		message by default.  Additional message for 1 comment or multiple
//		comments can still be used by including their text in the function
//		call or by using "#" to use the default text.
function comments_number( $zero='#', $one='', $more='' ) 
{
	if( $zero == '#' ) $zero = T_('Leave a comment');
	if( $one == '#' ) $one = T_('1 comment');
	if( $more == '#' ) $more = T_('% comments');
	
//////
//	Check to see if all messages should default to $zero text
	if( $one == '' ) $one = $zero;
	if( $more == '' ) $more = $zero;

	// original hack by dodo@regretless.com
	global $id,$postdata,$tablecomments,$c,$querycount,$cache_commentsnumber,$use_cache;
	$number = generic_ctp_number($id, 'comments');
	if ($number == 0) {
		$blah = $zero;
	} elseif ($number == 1) {
		$blah = $one;
	} elseif ($number  > 1) {
//////
//	REMOVED: 03.10.08 - Code rendered redundent by below code
//		$n = $number;
//		$more=str_replace('%', $n, $more);
		$blah = $more;
	}
	
	echo str_replace( '%', $number, $blah );	
} 


Travis

Oct 09, 2003 00:27

Just pass the same string 3 times! :P

Oct 24, 2003 12:44

I want a function to return just the number of comments (as a number).

It may then be wrapped to display textual message (like comments_number() does), but the raw number will be useful for number of other things.

I need it to display a number of comments in brackets after a post title in my list of 5 most recently commented posts.


Form is loading...

Build your own website! – This forum is powered by b2evolution CMS, a complete engine for your website.