您可以在函数中使用此自定义函数。主题php:
/**
* count for trackback, pingback, comment, pings
*
* embed like this:
* fb_comment_type_count(\'pings\');
* fb_comment_type_count(\'comment\');
*/
if ( !function_exists(\'fb_comment_type_count\') ) {
function fb_get_comment_type_count( $type=\'all\', $zero = false, $one = false, $more = false, $post_id = 0) {
global $cjd_comment_count_cache, $id, $post;
if ( !$post_id )
$post_id = $post->ID;
if ( !$post_id )
return;
if ( !isset($cjd_comment_count_cache[$post_id]) ) {
$p = get_post($post_id);
$p = array($p);
fb_update_comment_type_cache($p);
}
;
if ( $type == \'pingback\' || $type == \'trackback\' || $type == \'comment\' )
$count = $cjd_comment_count_cache[$post_id][$type];
elseif ( $type == \'pings\' )
$count = $cjd_comment_count_cache[$post_id][\'pingback\'] + $cjd_comment_count_cache[$post_id][\'trackback\'];
else
$count = array_sum((array) $cjd_comment_count_cache[$post_id]);
return apply_filters(\'fb_get_comment_type_count\', $count);
}
// comment, trackback, pingback, pings, all
function fb_comment_type_count( $type=\'all\', $zero = false, $one = false, $more = false, $post_id = 0 ) {
$number = fb_get_comment_type_count( $type, $zero, $one, $more, $post_id );
if ($type == \'all\') {
$type_string_single = __(\'Kommentar\', FB_BASIS_TEXTDOMAIN);
$type_string_plural = __(\'Kommentare\', FB_BASIS_TEXTDOMAIN);
} elseif ($type == \'pings\') {
$type_string_single = __(\'Ping und Trackback\', FB_BASIS_TEXTDOMAIN);
$type_string_plural = __(\'Pings und Trackbacks\', FB_BASIS_TEXTDOMAIN);
} elseif ($type == \'pingback\') {
$type_string_single = __(\'Pingback\', FB_BASIS_TEXTDOMAIN);
$type_string_plural = __(\'Pingbacks\', FB_BASIS_TEXTDOMAIN);
} elseif ($type == \'trackback\') {
$type_string_single = __(\'Trackback\', FB_BASIS_TEXTDOMAIN);
$type_string_plural = __(\'Trackbacks\', FB_BASIS_TEXTDOMAIN);
} elseif ($type == \'comment\') {
$type_string_single = __(\'Kommentar\', FB_BASIS_TEXTDOMAIN);
$type_string_plural = __(\'Kommentare\', FB_BASIS_TEXTDOMAIN);
}
if ( $number > 1 )
$output = str_replace(\'%\', number_format_i18n($number), ( false === $more ) ? __(\'%\', FB_BASIS_TEXTDOMAIN) . \' \' . $type_string_plural : $more);
elseif ( $number == 0 )
$output = ( false === $zero ) ? __(\'Keine\', FB_BASIS_TEXTDOMAIN) . \' \' . $type_string_plural : $zero;
else // must be one
$output = ( false === $one ) ? __(\'Ein\', FB_BASIS_TEXTDOMAIN) . \' \' . $type_string_single : $one;
echo apply_filters(\'fb_comment_type_count\', $output, $number);
}
}
此函数提供pingback、trackback、comments或all的计数,例如:
<h2 class="comments"><?php fb_comment_type_count( \'comment\' ); ?></h2>
可以使用以下参数返回计数器:comment、trackback、pingback、pings或all