JReviews logo
Guides My site
← All guides Community guide

Include cover and logo photos in the listing gallery

Alejandro
Thread started by Alejandro. Contributors Alejandro.
Thread started
Last updated

What you’ll achieve

Include cover and logo photos in the listing gallery.

My site

Platform
JReviews version

Include a listing's cover and logo photos in its detail-page gallery, even when those photos have a separate cover or logo role.

JReviews 6 Early Access

Enable Listing Detail Page in Early Access.

Include every published listing photo

The header and gallery normally serve different purposes. This override keeps the cover and logo in the header and includes those same photos in the Photos gallery. It replaces the Photos section with an inline gallery; it does not change the configured header layout.

Create resources/views/components/listings/detail/photos.blade.php in your JReviews overrides folder.

Joomla. Use templates/jreviews_overrides as the override root.

WordPress. Use jreviews_overrides as the override root.

@props(['listing'])
@php
    $galleryPhotos = $listing->getPhotos()->filter(fn ($photo) =>
        $photo->isPublished() && (! $listing->setting('media_detail_separate_media')
        || (int) $photo->owner_id === (int) $listing->owner_id)
    )->values();
    $galleryPhotos->loadMissing(['user', 'comment']);
@endphp
@if ($galleryPhotos->isNotEmpty())
    <x-jreviews::listing.section name="photos" :heading="fwd__('jreviews::site.headings.photos')" {{ $attributes }}>
        @if ($listing->setting('media_detail_separate_media') && ($userPhotoCount = $listing->userPhotos?->count()))
            <x-slot:header-end>
                <a href="{{ $listing->userPhotos->first()->urlSubmittedByUsers }}">{{ fwd_trans_choice('jreviews::site.action.view_user_photos.label', $userPhotoCount, ['count' => $userPhotoCount]) }}</a>
            </x-slot:header-end>
        @endif
        <x-jreviews::media.media-gallery :height="500" :listing="$listing" :media="$galleryPhotos" />
    </x-jreviews::listing.section>
@endif

Also create resources/views/components/listings/detail/sections/photos.blade.php in the same overrides folder. Copy the complete block below into it. Both files are needed: without this second override, a listing whose only photos are its cover and logo would still hide the Photos section.

@props(['listing', 'spacing' => '', 'editorComments' => null, 'userComments' => null])

<x-jreviews::listings.detail.photos :$listing :class="$spacing" />

The Photos section still stays hidden when the listing has no photos eligible for this gallery.

With separate user media enabled, another user's photos must remain outside the owner's gallery. Keep this override under review when updating JReviews because it replaces a core template.

JReviews 5 and v6 Legacy

Add the code to your overrides

Keep the customization in your JReviews overrides. Start a new PHP file with <?php followed by defined('MVC_FRAMEWORK') or die;. In an existing file, add the callback without repeating the opening tag or guard. If a snippet includes those lines, keep each only once.

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

WordPress. Use jreviews_overrides/filters/filter_functions.php.

Assigning a photo as the listing cover or logo normally removes it from the gallery. The following filter adds those photos back.

Add the PHP filter for the detail page

Clickfwd\Hook\Filter::add('post_get_listing_detailpage_query', function($listing, $params)
{
  foreach (['Cover', 'Logo'] as $function) {

    if (!isset($listing[$function])) continue;

    if ($listing[$function]['main_media']) {
       unset($listing['MainMedia']);
    }

    $listing['Media']['photo'][] = $listing[$function];
  }

  return $listing;

});

The loop checks both Cover and Logo. If either image is also the main media, the filter removes MainMedia so the photo can appear in the gallery.

Open a listing with a published cover, logo, and ordinary photo. Confirm that all three appear in the gallery and that the header keeps its configured cover and logo. Repeat with a listing whose only photos are its cover and logo, then a listing where either image is main media. Unpublished or inaccessible media must remain hidden. This customization does not add missing files or change list-page galleries.

Learn more