Posts: 8
Threads: 3
Joined: Feb 2011
I am using this programme to gain reviews for apartments listed on my site and would like the average star rating to appear on the individual apartments page and a page which lists all apartments.
Is there a bit of code which I can copy and paste for the average rating to show up on other (html) pages?
Many thanks.
Posts: 535
Threads: 31
Joined: Jul 2010
This is a quick answer. If you know a little PHP, you'll have to connect to the Commentics database (easily done by including "comments/includes/db/connect.php") and then run a query to get the reviews for the page you want. Here's the code used in Commentics for average ratings, for the general idea:
PHP Code:
<?php
//average rating
if ( $settings -> show_average_rating ) {
echo "<div class='average_rating_block'>" ;
$query_avg = mysql_query ( "SELECT AVG(rating) FROM `" . $mysql_table_prefix . "comments` WHERE is_approved = '1' AND rating != '0' AND page_id = ' $page_id '" );
$result_avg = mysql_fetch_assoc ( $query_avg );
$average_rating = round ( $result_avg [ "AVG(rating)" ]/ 0.5 )* 0.5 ;
$output_average_rating = '' ;
switch ( $average_rating ) {
case 1 :
$output_average_rating .= cmtx_star_full_avg ( 1 );
$output_average_rating .= cmtx_star_empty_avg ( 4 );
break;
case 1.5 :
$output_average_rating .= cmtx_star_full_avg ( 1 );
$output_average_rating .= cmtx_star_half_avg ( 1 );
$output_average_rating .= cmtx_star_empty_avg ( 3 );
break;
case 2 :
$output_average_rating .= cmtx_star_full_avg ( 2 );
$output_average_rating .= cmtx_star_empty_avg ( 3 );
break;
case 2.5 :
$output_average_rating .= cmtx_star_full_avg ( 2 );
$output_average_rating .= cmtx_star_half_avg ( 1 );
$output_average_rating .= cmtx_star_empty_avg ( 2 );
break;
case 3 :
$output_average_rating .= cmtx_star_full_avg ( 3 );
$output_average_rating .= cmtx_star_empty_avg ( 2 );
break;
case 3.5 :
$output_average_rating .= cmtx_star_full_avg ( 3 );
$output_average_rating .= cmtx_star_half_avg ( 1 );
$output_average_rating .= cmtx_star_empty_avg ( 1 );
break;
case 4 :
$output_average_rating .= cmtx_star_full_avg ( 4 );
$output_average_rating .= cmtx_star_empty_avg ( 1 );
break;
case 4.5 :
$output_average_rating .= cmtx_star_full_avg ( 4 );
$output_average_rating .= cmtx_star_half_avg ( 1 );
break;
case 5 :
$output_average_rating .= cmtx_star_full_avg ( 5 );
break;
}
if ( $average_rating != 0 ) {
echo $output_average_rating ;
echo "<span class='average_rating_text'>" ;
echo " " . CMTX_AVERAGE_RATING ;
echo "</span>" ;
}
Note that the pages must be php in order for this to work. If I find the time, I might get a full sample...
I'm giving you three guesses...
Posts: 8
Threads: 3
Joined: Feb 2011
Many thanks for the answer. I do not know too much PHP but will have a look and see if I can get it to work.
Thanks again for all the help. Great programme!
Posts: 116
Threads: 14
Joined: Aug 2011
Implementation (can be seen in action at www_kakteja_com) - everything is Google Rich Snippets ready:
1. part of html page, where php for stars data is called:
--------------------------------------------------------------------------------
<div class='zsm'>
<div class='hreview-aggregate'>
<span class='hidden_rating'>
<span class='item'>
<span class='fn'>
Šotori, tende, stojnice, bungalovi, paviljoni ... XX-XX zastopstvo in prodaja.
</span>
</span>
</span>
<table>
<tr>
<td valign='middle' class='blu'>
<a class='blo' title='Šotori, tende, stojnice ... E-Z UP! Ocene in komentarji.' href='/ocene-komentarji.php'> Komentarji in ocene </a>
</td>
<?php
$page_id = "1";
$mysql_table_prefix="" ;
$url_to_comments_folder="/slike/" ;
define ('IN_COMMENTICS', 'true');
$zvezd="vseb/zvezdje.php" ;
include $zvezd ;
?>
</tr>
</table>
</div>
</div>
2. css part
--------------------------------------------------------------------------------
.blu {
background-color: #5555ff;
padding-top: 0px;
padding-bottom: 0px;
padding-left: 10px;
padding-right: 10px;
}
.dlu {
background-color: #000055;
padding-top: 0px;
padding-bottom: 0px;
padding-left: 10px;
padding-right: 10px;
font-family: Arial,Helvetica,sans-serif;
font-size: 12px;
font-weight: 900;
text-decoration: none;
color: #ffffff;
}
.kbs {
padding-top: 0px;
padding-bottom: 0px;
padding-left: 5px;
padding-right: 5px;
}
.blo {
font-family: Arial,Helvetica,sans-serif;
font-size: 12px;
font-weight: 900;
text-decoration: underline;
color: #ffffff;
}
.blo:visited {
font-family: Arial,Helvetica,sans-serif;
font-size: 12px;
font-weight: 900;
text-decoration: underline;
color: #ffffff;
}
.blo:hover {
font-family: Arial,Helvetica,sans-serif;
font-size: 12px;
font-weight: 900;
text-decoration: underline;
color: #ffffff;
}
.stv {
position: relative;
height: 18px;
vertical-align: text-bottom;
}
.arb {
position: relative;
padding-left: 4px;
border-width: 1px;
border-style: solid;
border-color: transparent;
}
.hidden_rating {
display: none;
}
3. send .html over php processor, add into .htaccess (if needed)
-----------------------------------------------------------------------------------------------
AddHandler application/x-httpd-php5 .html .htm
4. upload .php file to document root and edit mysql connect data
-----------------------------------------------------------------------------------------------
Attached Files