Skip to content

Instantly share code, notes, and snippets.

@roose
Created May 29, 2011 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roose/997869 to your computer and use it in GitHub Desktop.
Save roose/997869 to your computer and use it in GitHub Desktop.
WordPress, retrieve the amount of comments a post has with russian plural form.
<?php
/**
* Retrieve the amount of comments a post has with russian plural form.
*
* @uses apply_filters() Calls the 'get_comments_number' hook on the number of comments
*
* @param int $post_id The Post ID
* @return int The number of comments a post has
*/
function russian_comments_number($zero = false, $one = false, $more = false, $deprecated = '') {
global $id;
$number = get_comments_number($id);
if ($number == 0) {
$output = 'Нет комментариев';
} elseif ($number == 1) {
$output = '1 комментарий';
} elseif (($number > 20) && (($number % 10) == 1)) {
$output = str_replace('%', $number, '% комментарий');
} elseif ((($number >= 2) && ($number <= 4)) || ((($number % 10) >= 2) && (($number % 10) <= 4)) && ($number > 20)) {
$output = str_replace('%', $number, '% комментария');
} else {
$output = str_replace('%', $number, '% комментариев');
}
echo apply_filters('russian_comments_number', $output, $number);
}
add_filter('comments_number', 'russian_comments_number');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment