Created
May 29, 2011 15:36
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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