May 23, 2013, 04:32:30 PM

Login with username, password and session length

FORUM POSTING GUIDELINES - Please read and follow them.

Pages: [1]
  Print  
Author Topic: Include Add favorite button in listing page (blogview, thumbview, or masonry)  (Read 1130 times)
Jon Lachlan
Full Member
***
Offline Offline

Posts: 57


« on: October 20, 2011, 02:02:17 PM »

Update: For JReviews 2.4, you can do this by simply adding this line of code to your listings template:

Code:
<?php $Widgets->favorite($listing);?>

--Original Post--
JRreviews version: 2.3.x

This should work in any custom listings page. I figured it out by looking at the code in the com_jreviews/jreviews/views/helpers/widgets.php file.

I'm going to use the template file listings_blogview.thtml as an example. Start by copying the file from the default template to your overrides folder, and giving it an _extension if you only want to the hack to apply to certain pages (or you can give it no extension and it will override default theme file). That means:
Copy from com_jreviews/jreviews/views/themes/default/listings/listings_blogview.thml to templates/jreviews_overrides/views/themes/my_theme/listings/listings_blogview_myextension.thtml

In JReviews backend, click the Clear File Registry button so that JReviews is aware of the new file in the jreviews_overrides folder. See the Documentation for setting up you theme overrides folder and configuration.

In the new custom theme file, find the favorites code
Code:
<?php if($this->Config->favorites_enable):?>
<span class="jrFavoriteWidget" title="<?php __t("Favorites"?>">
<span class="jrIcon jrIconFavorites"></span>
<span id="jr_favoriteCount<?php echo $listing['Listing']['listing_id'];?>"><?php echo $listing['Favorite']['favored'];?></span>
</span>
<?php endif;?>

And replace it with:
Code:
<?php if($this->Config->favorites_enable):?>
<span class="jrFavoriteWidget" title="<?php __t("Favorites"?>">
<span class="jrIcon jrIconFavorites"></span>
<span id="jr_favoriteCount<?php echo $listing['Listing']['listing_id'];?>"><?php echo $listing['Favorite']['favored'];?></span>
</span>
<?php if($listing['Favorite']['my_favorite']): ?>
           <span id="jr_favoriteImg<?php echo $listing['Listing']['listing_id'];?>" class="jrFavoriteButton jrButton" title="<?php __t("Remove from favorites");?>" onclick="jreviews.favorite.remove(this,{'listing_id':'<?php echo $listing['Listing']['listing_id'];?>'})"> <?php __t("Remove");?> </span>
         <?php elseif($User->id): ?>
           <span id="jr_favoriteImg<?php echo $listing['Listing']['listing_id'];?>" class="jrFavoriteButton jrButton" title="<?php __t("Add to favorites");?>" onclick="jreviews.favorite.add(this,{'listing_id':'<?php echo $listing['Listing']['listing_id'];?>'})"> <?php __t("Add");?> </span>
                                                        <?php else: ?>
           <span id="jr_favoriteImg<?php echo $listing['Listing']['listing_id'];?>" class="jrFavoriteButton jrButton" title="<?php __t("Add to favorites");?>" onclick="alert('<?php __t("Register to add this entry to your favorites");?>');"> <?php __t("Add");?> </span>
       <?php endif;?>
<?php endif;?>

Hope this helps Smiley

[Note: I updated the code to include an Add button for guests, which pops up with a registration alert when clicked]
« Last Edit: April 09, 2013, 11:41:04 AM by Jon Lachlan » Logged
Guilherme Dornelas
Full Member
***
Offline Offline

Posts: 50


« Reply #1 on: November 07, 2011, 04:33:30 PM »

Perfect!
Thanks a lot!
Logged
samira zaker soltani
Jr. Member
**
Offline Offline

Posts: 28


« Reply #2 on: June 09, 2012, 03:23:28 AM »

Great! Thankyou!
Logged
Blink
Sr. Member
****
Offline Offline

Posts: 150


« Reply #3 on: July 17, 2012, 08:00:01 PM »

Fantastic!!

THANKS Cheesy
Logged
doug hoseck
Newbie
*
Offline Offline

Posts: 13


« Reply #4 on: July 28, 2012, 06:44:32 AM »

Thank you for this solution. I managed to add this to both compact blogview and tableview. Worked like a charm Smiley
Logged
Brent Williams
Newbie
*
Offline Offline

Posts: 19


« Reply #5 on: September 27, 2012, 04:06:00 PM »

Jon, any chance you know how to add it to a module?  I'm surprised this is not a standard feature in the favorites module.

(Thanks in advance!)
Logged
Jon Lachlan
Full Member
***
Offline Offline

Posts: 57


« Reply #6 on: September 28, 2012, 08:40:40 AM »

Jon, any chance you know how to add it to a module?  I'm surprised this is not a standard feature in the favorites module.

So far I haven't gotten the favorite button to work in modules  Undecided I have tried both adding the code directly as above, as well as adding it as a widget like in Details view. None have worked so far...
Logged
Brent Williams
Newbie
*
Offline Offline

Posts: 19


« Reply #7 on: September 28, 2012, 09:25:48 AM »

Ok, thanks for the reply!
Logged
boxster99
Sr. Member
****
Offline Offline

Posts: 173


« Reply #8 on: April 09, 2013, 09:41:03 AM »

Hi Jon, that is a great job! I am wondering that is it possible to use on 2.4 version?
I tried that the "Favorites" button shown up on list page, but can't add favorites or remove favorites.
Thank you in advance!
Logged
Jon Lachlan
Full Member
***
Offline Offline

Posts: 57


« Reply #9 on: April 09, 2013, 11:07:12 AM »

Fortunately, this is much simpler in JReviews 2.4. Simply add the following to your template:

Code:
<?php $Widgets->favorite($listing);?>
Logged
boxster99
Sr. Member
****
Offline Offline

Posts: 173


« Reply #10 on: April 09, 2013, 12:01:50 PM »

Fortunately, this is much simpler in JReviews 2.4. Simply add the following to your template:

Code:
<?php $Widgets->favorite($listing);?>
Hi Jon, thank you for your kindly reply.
I am sorry about my bad sense on this issue. I am still not very clear where to add this code to.
Is it the index.php file in the template I need to add this code in?

Thank you!
Logged
Jon Lachlan
Full Member
***
Offline Offline

Posts: 57


« Reply #11 on: April 09, 2013, 12:06:53 PM »

The file is at components/com_jreviews/jreviews/views/themes/default/listings/listings_masonry.thtml

Then you add the line of code anywhere in the file that makes sense, e.g., inside div class="jrListingButtons" at line 107, like this:
Code:
<div class="jrListingButtons">

<?php $Widgets->listingManager($listing); /* LISTING MANAGER */?>

<?php $Widgets->compareCheckbox($listing); /* LISTING COMPARE */ ?>
<?php $Widgets->favorite($listing); /* <== ADDED FAVORITE BUTTON */ ?>

</div>

Once you get it working, you should copy this file to templates/jreviews_overrides/views/themes/MY_THEME/listings/listing_masonry.thtml and then clear the cache and file registry in JReviews admin.

Make sure you select MY_THEME (or whatever you call it -- it can be "default" if you want it to keep it simple) in the JReviews theme manager.
« Last Edit: April 09, 2013, 12:23:51 PM by Jon Lachlan » Logged
boxster99
Sr. Member
****
Offline Offline

Posts: 173


« Reply #12 on: April 09, 2013, 12:30:34 PM »

Hey Jon, you rock! It works perfectly!
Thank you very much!
Logged
Jon Lachlan
Full Member
***
Offline Offline

Posts: 57


« Reply #13 on: April 09, 2013, 12:45:55 PM »

Pleased I could help in my own little way. Of course the real credit goes to JReviews team for their great and flexible script. Not sure why they didn't include the fave button by default, but hey it's dead easy to add now.
Logged
boxster99
Sr. Member
****
Offline Offline

Posts: 173


« Reply #14 on: April 09, 2013, 01:04:29 PM »

Yes you are right! I am just on my beginning to learn Jreviews. Thanks Jreviews team bringing us a great component! I believe they will improve more in the coming release.
And thanks for this forum which provides us a good communication platform!
Good day Jon!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!