JReviews logo
Guides My site
← All guides Community guide

Add favorite buttons to list pages

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

What you’ll achieve

Let visitors add or remove favorites directly from listing list pages.

My site

Platform
JReviews version

Show a Favorite button on listing list pages so members can add or remove favorites without opening each listing.

Enable favorites for the listing type

Enable favorites in the applicable listing type settings. Keep a signed-in test user and a guest session for the final check. Adding a button does not grant favorite permission.

JReviews 6 Early Access

Show the built-in Favorite action

Enable Listing List Pages in Early Access. The standard card and table layouts already render Favorite as a heart icon in their compact action bars. No hook is needed.

If Favorite is missing from a customized layout, compare your override with the supplied template. A custom card needs the supplied footer section, which displays the action buttons. A list or table template needs its actions component. If that component has an include list of allowed buttons, keep favorite in it. Remove favorite from any exclude list of hidden buttons. Additional button conditions use the jreviews:listing:actions.listings_list hook described in the linked reference.

JReviews 5 and v6 Legacy

Add the Favorite callback

Add the callback to the legacy overrides file:

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 Favorite button to each listing in the list.

  • 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;

/* Add Favorite button to list page */
function add_favorite_button_list_page($buttons, $params)
{
   $listing = $params['listing'];

   $listingHelper = ClassRegistry::getClass('ListingHelperHelper');

   ob_start();

   $listingHelper->favorite($listing);

   $favoriteButton = ob_get_clean();

   $buttons['favorite'] = $favoriteButton;

   return $buttons;
}

Clickfwd\Hook\Filter::add('listing_list_action_buttons', 'add_favorite_button_list_page', 10);

Use a JReviews language string override to change the displayed favorite label. Adding the button does not change favorite behavior or turn it into a separate voting system.

Test adding and removing a favorite

Open a JReviews listing list page or search results page. Each eligible listing has its own Favorite control. As a signed-in visitor, add a favorite from the list and remove it again. Repeat as a guest to check the account prompt. Check a listing type with favorites disabled.

The modern Favorite button still checks permissions on the server. Showing the button in a custom layout does not give a visitor permission to use it. This guide does not add favorite counts or ordering by favorites. See Listing actions for action contexts and configuration.

Learn more