where is that function author_comment_count(); defined?
does it echo the result or return it?
for use in the conditional statement, you need a function that returns the value.
Thread Starter
tlw22
(@tlw22)
The author_comment_count(); is defined in the functions file:
// Displays no. comments
function author_comment_count(){
$oneText = '1';
$moreText = '%';
global $wpdb;
$result = $wpdb->get_var('
SELECT
COUNT(comment_ID)
FROM
'.$wpdb->comments.'
WHERE
comment_author_email = "'.get_comment_author_email().'"'
);
if($result == 1):
echo str_replace('%', $result, $oneText);
elseif($result > 1):
echo str_replace('%', $result, $moreText);
endif;
}
I’m not sure if the function is already returning the value, but if not, how can I get it to do so?
Thanks!
one possibility:
change the function to:
function author_comment_count($echo=1){
$oneText = '1';
$moreText = '%';
global $wpdb;
$result = $wpdb->get_var('
SELECT
COUNT(comment_ID)
FROM
'.$wpdb->comments.'
WHERE
comment_author_email = "'.get_comment_author_email().'"'
);
if($echo==0) : return $result;
elseif($result == 1):
echo str_replace('%', $result, $oneText);
elseif($result > 1):
echo str_replace('%', $result, $moreText);
endif;
}
the difference is, that the function can now use one parameter, which changes from ‘echo’ to ‘return’ if set to 0 (zero) – left empty, it will echo the result, if set to 0, it will return the result.
this should make no difference in the areas where you output the author comment count.
and now in your conditional statement, use it this way:
<?php if ( author_comment_count(0) <= 3 ) : ?>
// if a user has less than 3 comments display
<img src="image 1 here" />
<?php else: ?>
// otherwise display
<img src="image 2 here" />
<?php endif; ?>
Thread Starter
tlw22
(@tlw22)
Thanks, I will give it a go!
Thread Starter
tlw22
(@tlw22)
Yep, works perfectly. Thanks for all your help, much appreciated!