Skip to content

Instantly share code, notes, and snippets.

@bologer
Last active June 12, 2019 17:39
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 bologer/e4a0f361051b6e1ec00b68b29dac3e03 to your computer and use it in GitHub Desktop.
Save bologer/e4a0f361051b6e1ec00b68b29dac3e03 to your computer and use it in GitHub Desktop.
AnyComment получить рейтинг записи
<?php
// Функцию ниже нужно добавить в functions.php вашей темы
// Пример вывода в single.php: echo ac_get_post_rating(get_the_ID());
/**
* Возвращает рейтинг записи по ID записи.
*
* @see \AnyComment\Models\AnyCommentRating::get_average_by_post() для подробной информации.
* @return float
*/
function ac_get_post_rating ( $post_id ) {
if ( ! class_exists( '\AnyComment\Models\AnyCommentRating' ) ) {
return null;
}
$rating = \AnyComment\Models\AnyCommentRating::get_average_by_post( $post_id );
// тут вы можете сделать какую-то магию, например добавить нужный вам перевод для
// вывода в шаблон
// Например:
// return sprintf(__('Рейтинг: %s'), $rating);
return $rating;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment