Не нравятся результаты поиска? Попробуйте другой поиск!
DLE FAQ » Все вопросы » Хаки » Как вывести рейтинг новости в виде цифры?

Как вывести рейтинг новости в виде цифры?


     10.10.2016    Все вопросы » Хаки    3129

вопрос
Доброго времени суток. Как можно вывести в шаблонах среднюю оценку новости в виде числа? Допустим 4,6 - нужно для публикации в кратких новостях и в популярных

Ответил: Sander


Открыть файл engine/modules/show.***.php (3шт)
Найти строку:
$news_found = TRUE;

После нее вставить:
$tpl->set("{rate-val}", $row['vote_num']>0?round($row['rating']/$row['vote_num'],1):0);


В шаблоне использовать тег:
{rate-val}

Для topnews, открыть файл engine/modules/topnews.php
Найти строку:
while ( $row = $db->get_row() ) {

И после нее вставить вышеуказанный код.

3 комментария

vaniya92
Юзер

vaniya92 - 11 октября 2016 19:00 -

Спасибо, то что нужно)

arneon
Юзер

arneon - 23 октября 2019 16:47 -

работает, но как сделать, чтобы при средней оценке 4.5 цветом заливались четыре с половиной звезды, а не 5?

arneon
Юзер

arneon - 28 октября 2019 16:53 -

Цитата: arneon
работает, но как сделать, чтобы при средней оценке 4.5 цветом заливались четыре с половиной звезды, а не 5?

находите в engine/modules/function.php строку
function ShowRating($id, $rating, $vote_num, $allow = true) {

и заменяйте её на
function ShowRating($id, $rating, $vote_num, $allow = true) {
	global $lang, $config, $row, $dle_module;

	if( !$config['rating_type'] ) {
		
		if($rating AND $vote_num) {
			$rating = round(($rating / $vote_num), 1);
		} else {
			$rating = 0;
		}
		
		if ($rating < 0 ) $rating = 0;
		
		if ($vote_num AND $dle_module == "showfull") {
			
			$shema_title = " itemprop=\"aggregateRating\" itemscope itemtype=\"http://schema.org/AggregateRating\"";
			$shema_ratig = $rating;
			$shema_ratig_title = str_replace("&", "&",  htmlspecialchars( strip_tags( stripslashes( $row['title'] ) ), ENT_QUOTES, $config['charset'] ) );
			$shema = "<meta itemprop=\"itemReviewed\" content=\"{$shema_ratig_title}\"><meta itemprop=\"worstRating\" content=\"1\"><meta itemprop=\"ratingCount\" content=\"{$vote_num}\"><meta itemprop=\"ratingValue\" content=\"{$shema_ratig}\"><meta itemprop=\"bestRating\" content=\"5\">";

		} else {
			$shema_title = "";
			$shema = "";
		}
		
		$rating = floor($rating * 20);
	
		if( !$allow ) {
		
			$rated = <<<HTML
<div class="rating"{$shema_title}>
		<ul class="unit-rating">
		<li class="current-rating" style="width:{$rating}%;">{$rating}789</li>
		</ul>{$shema}
</div>
HTML;
		
			return $rated;
		}
	
		$rated = <<<HTML
<div id='ratig-layer-{$id}'>
	<div class="rating"{$shema_title}>
		<ul class="unit-rating">
		<li class="current-rating" style="width:{$rating}%;">{$rating}</li>
		<li><a href="#" title="{$lang['useless']}" class="r1-unit" onclick="doRate('1', '{$id}'); return false;">1</a></li>
		<li><a href="#" title="{$lang['poor']}" class="r2-unit" onclick="doRate('2', '{$id}'); return false;">2</a></li>
		<li><a href="#" title="{$lang['fair']}" class="r3-unit" onclick="doRate('3', '{$id}'); return false;">3</a></li>
		<li><a href="#" title="{$lang['good']}" class="r4-unit" onclick="doRate('4', '{$id}'); return false;">4</a></li>
		<li><a href="#" title="{$lang['excellent']}" class="r5-unit" onclick="doRate('5', '{$id}'); return false;">5</a></li>
		</ul>{$shema}
	</div>
</div>
HTML;
	
		return $rated;

	} elseif ($config['rating_type'] == "1") {
		
		if( $rating < 0 ) $rating = 0;
		
		if( $allow ) $rated = "<span id=\"ratig-layer-{$id}\" class=\"ignore-select\"><span class=\"ratingtypeplus ignore-select\" >{$rating}</span></span>";
		else $rated = "<span class=\"ratingtypeplus ignore-select\" >{$rating}</span>";
		
		return $rated;
	
	} elseif ($config['rating_type'] == "2" OR $config['rating_type'] == "3") {
		
		$extraclass = "ratingzero";
		
		if( $rating < 0 ) {
			$extraclass = "ratingminus";
		}
		
		if( $rating > 0 ) {
			$extraclass = "ratingplus";
			$rating = "+".$rating;
		}
		
		if( $allow ) $rated = "<span id=\"ratig-layer-{$id}\" class=\"ignore-select\"><span class=\"ratingtypeplusminus ignore-select {$extraclass}\" >{$rating}</span></span>";
		else $rated = "<span class=\"ratingtypeplusminus ignore-select {$extraclass}\" >{$rating}</span>";
		
		return $rated;
		
	}

Чтобы комментировать - войдите или зарегистрируйтесь на сайте

Похожие вопросы

наверх