Link to the listing owner from a banner field
- Thread started
- Last updated
What you’ll achieve
Display the listing owner name as a link to that owner’s listings.
My site
Show each listing owner's name as a link to that owner's listings in a banner custom field. The link uses the listing owner, regardless of who is viewing the page. For example, show Partner beneath each hotel in a Listings widget. Clicking the hotel chain's name opens that partner's other listings. A banner is an output field, so visitors do not need to enter the owner in another form field.
Prepare the banner field
Create a listing custom field with type Banner, or choose an existing banner for the owner link. Choose a listing field group in the field editor. Open each listing type where the link should appear and include that group in its Field Groups selection. An existing associated group also works. Enable the banner in the display locations where you want the owner link.
JReviews 6 Early Access
Add the owner link to the banner
For a listing detail page, enable Listing Detail Page in Configuration > Early Access Settings. For a list page, enable Listing List Pages. A modern Listings widget renders its own field output independently of these page switches. Enable the banner in that widget if you place the owner link there.
In Advanced Settings > Blade template code, paste the following template.
@php
$ownerId = (int) $listing->owner_id;
$ownerName = (string) $listing->owner_name;
$ownerMenu = fwd_app(\JReviews\App\Contracts\CmsHelpers\MenuFinderContract::class)
->findByRoute('categories.mylistings');
$ownerUrl = $ownerId > 0
? $ownerMenu->permalink($ownerMenu->exists() ? '' : 'categories/mylistings', ['user' => $ownerId])
: null;
@endphp
@if ($ownerUrl)
<a href="{{ $ownerUrl }}">{{ $ownerName }}</a>
@endif
To show it in a Listings widget, include this field in that widget's displayed custom fields. The link uses the listing owner's ID, so it does not change when a different visitor signs in. Listings without a registered owner do not show a link.
To display the account username instead, replace the $ownerName assignment with $ownerName = (string) $listing->user->username;. Keep $ownerId unchanged.
Publish a My Listings page to use your chosen URL for the link. Without one, JReviews uses its fallback route. Test the destination as a guest too, because listing publication and access settings still control which results are visible.
JReviews 5 and v6 Legacy
Add the banner PHP format
Put this code in the banner field's PHP format setting.
Joomla. Enable the field among the displayed fields of your legacy Latest Listings module.
WordPress. Enable the field among the displayed fields of your legacy Latest Listings widget.
$Routes = new RoutesHelper;
return $Routes->myListings($entry['User']['name'], $entry['User']['user_id']);
JReviews provides $entry there for the listing being displayed. RoutesHelper::myListings builds the link from the owner's name and user ID. Do not run the example as a standalone PHP script.
To display the username instead of the real name, change $entry['User']['name'] to $entry['User']['username']. Keep user_id unchanged.
Check the owner link
Open listings belonging to different owners. Follow each banner link and confirm that it opens that owner's listings. Repeat while signed out and while signed in as someone else. Listing publication and access settings still control which results visitors can see. Check a listing without a registered owner too.