Adding related listings to listing detail page

From JReviews Documentation
Jump to: navigation, search

Make sure you also read the article on Listing Detail Page Widgets. The easiest way to describe what you can do with related listings is to use some examples. Let's say you have a movie directory where you have both actor and movie listings. With related listings you can show movies for each actor's listing. The same can be applied to manufacturers and products, venues and events, etc. You will need to have a common custom field that exists in both types of listings to make the association. In the actor's example, you would need to include the actor field in both the actor listing and the movie listing.

For even more options on embedding the listing module in detail pages read the article Adding custom JReviews modules into listing detail pages

Basic usage

You can add a Related listings "module" to your listing detail page to display related listings based on a common custom field. This is a hack of the Listings Module.

The code you need to enter in detail.thtml file to display related listings is:

<?php echo $this->element('related_listings',array('field'=>'jr_name','suffix'=>''));?>

Replace jr_name with the name of your custom field.


For a hotel/restaurant listings, you can use jr_city custom field to display related listings based on City:

<h2>Related Listings</h2>
<?php echo $this->element('related_listings',array('field'=>'jr_city','suffix'=>''));?>

When viewing a certain New York listing, the above code will display the related New York listings:



To see the different settings that can be passed in the related listings call, view this file:

  • \com_jreviews\jreviews\views\themes\default\elements\related_listings.thtml

Since Related listings module is an extension of the Listings module, it uses the same theme file:

  • \com_jreviews\jreviews\views\themes\default\modules\listings.thtml

Modifying the related listings theme file

To modify the theme for related listings output only, create a copy and add a suffix to the file, for example: listings_related.thtml

To use that theme add '_related' suffix into the code:

<?php echo $this->element('related_listings',array('field'=>'jr_name','suffix'=>'_related'));?>

Passing additional settings to the related listings call

Additional settings can be passed in 2nd settings array of the $this->element class method. You can combine any of the settings shown below by adding them to the array separated by comma.

Limiting results to a single category

<?php echo $this->element('related_listings',array('field'=>'jr_name','cat_id'=>'10'));?>

Limiting results to several categories

<?php echo $this->element('related_listings',array('field'=>'jr_name','cat_id'=>'10,11,12'));?>

Changing the number of listings and columns

<?php echo $this->element('related_listings',array('field'=>'jr_name','limit'=>6,'total'=>24,'cols'=>3));?>

Enabling category auto-detect

<?php echo $this->element('related_listings',array('field'=>'jr_name','cat_auto'=>true,'limit'=>2,'cols'=>2));?>