Jump to content

Subscribe Button on Listview


JoshLewis

Recommended Posts

Inspired by the Favorites on Listview function I decided to create an EngageUsers subscribe button for list view:

sub.png.6e9c1b72a2555b775a30abd64ffd3ea0.png

The following code utilizes filter_functions.php for adding the subscribe button to listview:

/* Add Subscribe button to list page */

function add_subscribe_button_list_page($buttons, $params)
{
   
   $listing = $params['listing'];
   $listing_id = (int) $listing['Listing']['listing_id'];
   
   ob_start();?>
   <span data-jr-follow="">
	<a class="jrFollowButton jrButton jrSmall jrOrange" data-jr-action="dialog" data-jr-dialog-modal="true" data-jr-width="512" data-jr-title="Follow" rel="nofollow" href="/preferences?task=createFollow&app=jreviews&area=listing&rel_id=<?php echo $listing_id;?>">
		<span class="jrIconBell"></span>Follow
     </a>
    </span>
		<?php
		$subscribeButton = ob_get_clean();
		$buttons['subscribe'] = $subscribeButton;
   return $buttons;
}

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

Because I want both a favorites button and a subscribe button I simply combine them into a single function:

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;
   
   // Show subscribe button
   
   $listing_id = (int) $listing['Listing']['listing_id'];
   ob_start();?>
   <span data-jr-follow="">
	<a class="jrFollowButton jrButton jrSmall jrOrange" data-jr-action="dialog" data-jr-dialog-modal="true" data-jr-width="512" data-jr-title="Follow" rel="nofollow" href="/preferences?task=createFollow&app=jreviews&area=listing&rel_id=<?php echo $listing_id;?>">
		<span class="jrIconBell"></span>Follow</a></span>
		<?php
		$subscribeButton = ob_get_clean();
		$buttons['subscribe'] = $subscribeButton;

   return $buttons;
}
Clickfwd\Hook\Filter::add('listing_list_action_buttons', 'add_favorite_button_list_page', 10);

The href points to /preferences which is the name of my preferences page/menu-item. You'll need to change the 'preferences' text to the alias of the page for it to properly work.

Another handy thing to do is wrapping the inner function code with conditions to display it such as:

$listing_type_id = $listing['ListingType']['listing_type_id'];
if ( $listing_type_id == 1 ) :
    // code that runs if listing type 1
endif;

More variables to write conditions for can be found here: https://www.jreviews.com/docs/theme-resources/discover-data-available-in-templates#listing-variables

Edited by JoshLewis
  • Like 2
Link to post
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Please refer to our Privacy Policy.