JReviews logo
Guides My site
← All guides Community guide

Use cover images for listing thumbnails

G Alejandro
Thread started by GJNR. Contributors GJNR, Alejandro.
Thread started
Last updated

What you’ll achieve

Use cover photos as listing thumbnails, with the main photo as a fallback.

My site

Platform
JReviews version

Show cover photos as thumbnails in one selected Listings widget while leaving other widgets unchanged.

JReviews 6 Early Access

Use cover thumbnails in one Listings widget

Start with a published saved Listings widget that is already visible on your site and shows listing thumbnails. If you need to create and place one first, follow Site Widgets. Confirm it shows a listing with an uploaded cover and another listing without one. To give a listing a cover, open the listing, select Upload media, upload a photo, and choose it as the cover.

Open that widget in Setup > Site Widgets. In its Embed panel, find the shortcode and copy the value inside id="...". That value is the widget's Shortcode ID, not the number in the ID column. The template example uses cover-thumbnails; replace it with the value you copied.

Copy the installed JReviews template resources/views/site/components/widget/listings.blade.php into your overrides folder as resources/views/components/widget/listings.blade.php. Create the missing folders.

Joomla. Copy the installed template from components/com_jreviews/resources/views/site/components/widget/listings.blade.php. Use templates/jreviews_overrides as the override root.

WordPress. Copy the installed template from wp-content/plugins/jreviews/resources/views/site/components/widget/listings.blade.php. Use jreviews_overrides as the override root.

On the listing card, below the :url="$listing->url" line, replace the :image attribute. In the block below, the line marked with - is the current attribute, and the lines marked with + replace it. The dimmed lines stay as they are.

:image-alt="$listing->title"
:url="$listing->url"
:image="$listing->listImageSrc('medium')"
:image="(string) $widget->unique_id === 'cover-thumbnails' && $listing->coverPhoto->exists
    ? ($listing->coverPhoto->medium ?: $listing->listImageSrc('medium'))
    : $listing->listImageSrc('medium')"
:rating-rows="$ratingRows"

Replace cover-thumbnails with the saved widget's real identifier. The targeted widget uses an uploaded cover when available. A listing without a cover keeps its normal thumbnail. Other widgets keep their normal thumbnails too. This targets saved widgets; a generated listings shortcode has a different, temporary identifier.

Keep the rest of the copied template unchanged. Compare the override with the installed template after JReviews updates.

JReviews 5 and v6 Legacy

Joomla. Show the listing cover instead of its main thumbnail in a legacy Listings module.

WordPress. Show the listing cover instead of its main thumbnail in a legacy Listings widget.

Listings without a cover keep their main image. This changes the data supplied to the selected instance, so its existing thumbnail template needs no edit.

Find the module or widget ID

Joomla. Obtain the numeric ID of the Listings module you want to change. Replace 123 below with that ID.

WordPress. Find the saved widget ID with the administrator inventory in Keep city content in the CMS sidebar. Match the sidebar and widget position, then copy that widget's ID. Replace 123 below with the complete ID inside the quotes. Do not use a post or page ID.

The comparison converts both values to strings.

Add the PHP filter to your overrides

Joomla. Use templates/jreviews_overrides/filters/filter_functions.php.

WordPress. Use jreviews_overrides/filters/filter_functions.php.

Add the callback marked with +. It adds the cover to the listings in one module or widget instance.

  • If filter_functions.php already exists, add the marked lines at the end of the file. The copy button copies only those lines.
  • If you are creating filter_functions.php, type the two dimmed lines first, then add the marked lines below them.
<?php
defined('MVC_FRAMEWORK') or die;

Clickfwd\Hook\Filter::add('post_get_listings_listings_module_query', function ($listings, $params) {
	$targetInstanceId = '123';
	$instanceId = (string) ($params['params']['module_id'] ?? '');

	if ($instanceId !== $targetInstanceId) {
		return $listings;
	}

	$config = S2Object::make('config');
	$Media = new MediaModel;
	$listings = $Media->addMedia($listings, 'Listing', 'listing_id', [
		'sort' => $config->media_general_default_order_listing,
		'extension' => 'com_content',
		'controller' => 'com_content',
		'action' => 'com_content_view',
	]);

	foreach ($listings as &$listing) {
		if (!empty($listing['Cover'])) {
			$listing['MainMedia'] = $listing['Cover'];
		}
	}
	unset($listing);

	return $listings;
});

Keep thumbnails enabled in that instance. The code uses a cover when that listing has one, keeps the normal thumbnail when it does not, and leaves other modules or widgets unchanged.

Clear Cache & File Registry after adding the override.

Check covers and fallback

Display one listing with a cover and one with only a regular photo in the selected instance. Confirm that the first uses its cover and the second keeps its normal thumbnail. Compare another Listings instance on the same page and confirm its thumbnails remain unchanged.

Learn more