Show user ratings beside related listings
- Thread started
- Last updated
What you’ll achieve
Show user ratings beside other consultants who belong to the same agency.
My site
Show other consultants at the same agency on a consultant detail page, with each consultant's own published user rating.
Create the agency relationship
Create Agency and Consultant listing types, with a category for each. Publish two Agency listings named Harbor Agency and Summit Agency.
In Setup > Field Groups, create a listing field group with the title Consultant details and the name consultantdetails, or reuse a group already associated with Consultant. In Setup > Fields, create a listing Related Listing field labeled Agency. In Name, type agentur; JReviews adds the jr_ prefix, so the field name becomes jr_agentur. Do not type the prefix yourself, or the name becomes jr_jragentur. Select Consultant details as its field group. In the Consultant listing type's Field Groups settings, associate that same group. Keep the group exclusive to Consultant for this example.
For Agency, set Related Listings Form Filters > Listing type to Agency and Maximum options that can be selected to 1. Keep the field active, optional, and without dependencies. Keep the default access settings, which let editors fill in the field and visitors see it. Editors choose an existing Agency listing when they create or edit a consultant. Do not create predefined field options.
Publish three Consultant listings named Alex, Blair, and Casey. Select Harbor Agency for Alex and Blair, and Summit Agency for Casey. If Harbor Agency is listing 201 and Summit Agency is listing 202, Alex and Blair both store 201 in jr_agentur, while Casey stores 202. The IDs are examples. Select your own agency records.
In the Consultant listing type, allow comments and ratings, enable user reviews, and configure at least one rating criterion such as Service. You can leave its Weight at the default. Allow user ratings to display. Submit and publish a user review for Blair, for example a Service score of 4 on a site already using a five-point scale. The related result must display Blair's own published score, not the agency's score.
Choose a rated related listing
Choose a related listing that has published user ratings. Confirm that its listing type allows those ratings to be displayed. Follow the steps below for your related-listings layout. A custom relation-field layout may need different options.
JReviews 6 Early Access
Enable ratings in the component
Requires Listing Detail Page in Early Access.
Use the Agency field and the three consultants prepared above. To show other consultants at the same agency with their stars:
- Open the consultant listing type and its Detail Page Widgets settings.
- Add or edit an enabled related-listings widget. Give it a title such as "Other consultants at this agency".
- Set Find Listings Where to The specified field matches the current listing field of the same name.
- Set Field Name to
jr_agentur. Replace that name if your field has a different name. - Select the consultant listing type as the source of results. Choose a layout and the number of results.
- Enable Show User Rating. Enable Show Editor Rating if you also want editor scores. Save the listing type.
Open Alex. The widget shows Blair with Blair's own rating, excludes Alex, and does not show Casey or either agency. An empty Agency field produces no matching widget output.
The modern listing detail layout must include its RelatedListings component. Keep that component if you customize the detail layout.
The related entry's own rating visibility settings still apply; the widget switch does not force hidden ratings to appear. See Related Listings detail-page widgets.
JReviews 5 and v6 Legacy
Add ratings to your detail template
In Configuration > General, enable Theme Explorer. Open a consultant detail page and identify its active detail template in the Theme Explorer output. It may be listings/detail.thtml, listings/detail_tabs.thtml, or another suffixed detail template. Copy that active file into your custom JReviews theme, keeping its filename and relative path. For an active detail_tabs.thtml template and a custom theme named mysite, use the path below. If Theme Explorer shows another filename, substitute it in the path.
Joomla. Save the override as templates/jreviews_overrides/views/themes/mysite/listings/detail_tabs.thtml.
WordPress. Save the override as jreviews_overrides/views/themes/mysite/listings/detail_tabs.thtml.
Select mysite as your custom theme in JReviews. Keep the rest of your detail template.
Prepare the same-agency element
Copy elements/related_listings.thtml from your installed JReviews theme into your custom theme, naming the copy elements/agency_consultants.thtml. Keep the original file unchanged.
Save your copy as templates/jreviews_overrides/views/themes/mysite/elements/agency_consultants.thtml.
Save your copy as jreviews_overrides/views/themes/mysite/elements/agency_consultants.thtml.
In the copied element, below the $dir = ... line, replace the $fieldValues and $isMultipleOption statements with the new code. In the block below, the lines marked with - are the ones you remove, and the lines marked with + are the ones you add in their place. The dimmed lines stay as they are.
$dir = $dir_id ?? $dir ?? '';
$fieldValues = $CustomFields->fieldValue($field,$listing);
$isMultipleOption = $CustomFields->isMultipleOption($field,$listing);
$fieldData = $listing['Field']['pairs'][$field] ?? [];
$consultantTypeId = (int) ($listing['ListingType']['listing_type_id'] ?? 0);
if ($field !== 'jr_agentur' || ($fieldData['type'] ?? '') !== 'relatedlisting' || $consultantTypeId < 1) {
return;
}
$fieldValues = array_values(array_filter(array_unique(array_map('intval', (array) ($fieldData['real_value'] ?? []))), static fn ($id) => $id > 0));
if ($fieldValues === []) {
return;
}
$isMultipleOption = true;
if(!empty($fieldValues) && !is_array($fieldValues))
A Related Listing field stores listing IDs separately from the links it displays. This element uses the saved agency IDs to find consultants whose Agency field contains the same ID. If the field is empty, the element displays nothing.
In the same file, find the $params array. Inside its nested 'module' array, add the line marked with + below the 'category' entry:
'dir' => $dir ?? '', // Directory filter
'category' => $category ?? '', // Category filter
'criteria' => $consultantTypeId,
'listing' => '', // Listing filter
This restricts results to the current consultant's listing type. Keep the element's other settings and its final requestAction call. They provide the normal publication filters, current-listing exclusion, result limit, and rating output.
Display the element on the consultant page
In the active detail template override you identified above, add this call where the consultant results should appear, for example below the listing's description or media:
<?php echo $this->element('agency_consultants',array('field'=>'jr_agentur','user_rating'=>true,'suffix'=>''));?>
If you use a different Agency field name, replace jr_agentur in both this call and the new element's field-name check. Keep user_rating set to true. The score beside Blair belongs to Blair's listing, not to Harbor Agency. After saving both override files, run Clear Cache & File Registry in JReviews. Turn off Theme Explorer and reopen Alex's detail page.
Open a listing and check the related entries' stars
JReviews 6 Early Access. Check the component's Show User Rating setting and the related entry's own rating visibility. Open a listing with rated related entries and confirm their stars appear.
JReviews 5 and v6 Legacy. Open Alex and check that Blair appears with Blair's user rating. Alex, Casey, and both agency listings must be absent. Also check an empty Agency field and a consultant whose agency has no other consultants.
If stars do not appear, check that the related listings have published ratings, that their display settings permit those ratings, and that your template renders them. Setting user_rating does not create missing ratings or override every field display setting.
Learn more
- Themes (v5)
- File Overrides (v5)
- Themes (v6)
- File Overrides (v6)
- Related Listings (v6)
- Early Access (v6)