Originally Posted by
MagicMan
Can we display Product reviews on the product page without clicking "Read Reviews"?
Why yes you can.. the heard part is deciding on layout.
I use a modified version of the Average Product Rating mod, then setup code to display the reviews in a expanding dropdown tab. the link will take to one of my products that has a review.
Lantern
the code side is really simple, add database query to the page variables, add code to the template to display the query... this is what's on my page so you may have to weed out what you don't need...
includes/modules/pages\product_info/main_template_vars.php
Code:
// if review must be approved or disabled do not show review
$review_status = " and r.status = '1'";
$reviews_query = "select count(*) as count from " . TABLE_REVIEWS . " r, "
. TABLE_REVIEWS_DESCRIPTION . " rd
where r.products_id = '" . (int)$_GET['products_id'] . "'
and r.reviews_id = rd.reviews_id
and rd.languages_id = '" . (int)$_SESSION['languages_id'] . "'" .
$review_status;
$reviews = $db->Execute($reviews_query);
// 2P added BOF - Average Product Rating
$reviews_average_rating_query = "select avg(reviews_rating) as average_rating from " . TABLE_REVIEWS . " r, "
. TABLE_REVIEWS_DESCRIPTION . " rd
where r.products_id = '" . (int)$_GET['products_id'] . "'
and r.reviews_id = rd.reviews_id
and rd.languages_id = '" . (int)$_SESSION['languages_id'] . "'" .
$review_status;
$reviews_average_rating = $db->Execute($reviews_average_rating_query);
$reviews_query_raw = "select *
from " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd
where r.products_id = '" . (int)$_GET['products_id'] . "'
and r.reviews_id = rd.reviews_id
and rd.languages_id = '" . (int)$_SESSION['languages_id'] . "'" .
$review_status;
$reviews_split = new splitPageResults($reviews_query_raw, 10);
// 2P added EOF - Average Product Rating
then on the product page I used this to dispaly it inside a expanding tab
includes/template/YOURTEMPLATE/templates/tpl_product_info_display.php
Code:
<div class="content1">
<?php
if ($reviews_split->number_of_rows > 0) {
?>
<div id="reviewsDefaultListingTopNumber" class="navSplitPagesResult"><?php echo $reviews_split->display_count(TEXT_DISPLAY_NUMBER_OF_REVIEWS); ?></div>
<div id="reviewsDefaultListingTopLinks" class="navSplitPagesLinks"><?php echo TEXT_RESULT_PAGE . ' ' . $reviews_split->display_links(MAX_DISPLAY_PAGE_LINKS, zen_get_all_get_params(array('page', 'info', 'main_page'))); ?></div>
<?php
$reviews = $db->Execute($reviews_split->sql_query);
while (!$reviews->EOF) {
?>
<hr />
<div class="bold"><?php echo sprintf(TEXT_REVIEW_BY, zen_output_string_protected($reviews->fields['customers_name'])); ?></div>
<div class="content">
<?php echo sprintf(TEXT_REVIEW_DATE_ADDED, zen_date_short($reviews->fields['date_added'])); ?><br />
<?php echo zen_output_string_protected(stripslashes($reviews->fields['reviews_text'])); ?></div>
<div class="rating"><?php echo zen_image(DIR_WS_TEMPLATE_IMAGES . '/rat_' . $reviews->fields['reviews_rating'] . '.gif', sprintf(TEXT_OF_5_STARS, $reviews->fields['reviews_rating'])), sprintf(TEXT_OF_5_STARS, $reviews->fields['reviews_rating']); ?></div>
<?php
$reviews->MoveNext();
}
?>
<?php
} else {
?>
<div id="reviewsDefaultNoReviews" class="content"><?php echo TEXT_NO_REVIEWS; ?></div>
<?php
}
?>
<span class="forward"><?php echo '<a href="' . zen_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, zen_get_all_get_params(array())) . '">' . zen_image_button(BUTTON_IMAGE_WRITE_REVIEW, BUTTON_WRITE_REVIEW_ALT) . '</a>'; ?></span>
</div>
Bookmarks