listing_status_labels

Filter Hook Listings

Allows adding and removing labels (e.g. featured, new, popular)

$labels is an array of current labels to be shown. Each element in the array accepts the following keys:

  • text: the label text
  • title: used in HTML title attribute for the label
  • class: string of CSS classes appended to the default jrStatusLabel class.
  • override_class: boolean value indicating whether CSS classes in class key should replace the entire class attribute. When set to true, this removes the jrStatusLabel class from the label output

Parameters

$labels

(array)

$params

(array) associative array with contextual data

You need to have a working knowledge of Hooks before you get started.

Boilerplate Code

Use the boilerplate code to start using the filter, and add your own logic to modify the first argument and return it.

Clickfwd\Hook\Filter::add('listing_status_labels', function($labels, $params) 
{
  // Uncomment line below to view available data passed into hook
  // For JReviews 3.x and earlier use dd instead of fwd_dd
  // fwd_dd($labels, $params);
  
  return $labels;
});
Development & Support
Customizations are not included with support. We provide this information to make it easier for developers to extend the functionality. From time to time we may have some availability for custom work. Get in touch to see if there's an opportunity to work together.

Examples

Custom Field as Label

Shows output of text, single select or radiobutton custom field named jr_status as a label.

In this example we are using field options with open and closed values and we include those in the label class attribute to style the label with CSS.

Add the CSS below to custom_styles.css in your custom theme or to your site's CSS overrides.

.jrStatusLabel.open {
   background-color: #468847;
}
.jrStatusLabel.closed {
   background-color: #b94a48;
}
function status_field_label($labels, $params)
{
    $listing = $params['listing'];
 
    // Text, single select and radio button custom fields
 
    $statusText = $listing['Field']['pairs']['jr_status']['text'][0] ?? null;
 
    $statusValue = $listing['Field']['pairs']['jr_status']['value'][0] ?? null;
 
    if ( $statusText )
    {
	    $label = [
	      'class'=>'jrStatusLabel '.$statusValue,
	      'text'=>$statusText
	    ];    	
 
      	// Add new label in the first position

      	array_unshift($labels, $label);
    }
  
    return $labels;
}
 
Clickfwd\Hook\Filter::add('listing_status_labels', 'status_field_label', 10);

Label with Listing Type Title

function listing_type_label($labels, $params)
{
    $listing = $params['listing'];
 
    $listingType = (S2App::make('listing_type'))->getById($listing['ListingType']['listing_type_id']);
 
    // Label color CSS classes:
  	// jrRed, jrOrange, jrBlue, jrGreen, jrBrown, jrPurple, jrBrown
 
    $label = [
      'class'=>'jrStatusLabel jrRed', 
      'text'=>$listingType['ListingType']['title']
    ];
 
    // Add new label in the first position
    
  	array_unshift($labels, $label);
 
    return $labels;
}
 
Clickfwd\Hook\Filter::add('listing_status_labels', 'listing_type_label', 10);

Add Custom Plan Labels for Paid Listings

function paid_plan_labels($labels, $params)
{
    $listing = $params['listing'];
 
    $planIds = $listing['Paid']['plan_ids'] ?? [];
  
  	if (empty($planIds)
    {
    	return $labels;
    }
 
    $basicPlanId = 1;
    $premiumPlanId = 2;
 
  	// Label color CSS classes:
  	// jrRed, jrOrange, jrBlue, jrGreen, jrBrown, jrPurple, jrBrown
  
    if (in_array($basicPlanId, $planIds))
    {
      $labels['basic'] = [
      'class'=>'jrStatusLabel jrPurple', 
      'text'=>'Basic Plan'
      ];
    }
 
    if (in_array($premiumPlanId, $planIds))
    {
      $labels['premium'] = [
      'class'=>'jrStatusLabel jrGreen',
      'text'=>'Premium Plan'
      ];
    }
 
    return $labels;
}
 
Clickfwd\Hook\Filter::add('listing_status_labels', 'paid_plan_labels', 10);

Source

  • /views/helpers/listing_helper.php