May 21, 2013, 07:40:09 AM

Login with username, password and session length

FORUM POSTING GUIDELINES - Please read and follow them.

Pages: [1]
  Print  
Author Topic: Trick for display listing data only when a link is clicked  (Read 815 times)
mikkox
Hero Member
*****
Offline Offline

Posts: 265


« on: March 10, 2011, 05:41:56 AM »

Do you need to show a value coming from a listing field but only when a link is clicked before? This tricks is useful if you want display data (like phone number) without let search engine crawl this data.

For do that follow this little tutorial:

1) Assuming you want apply this tricks to your Phone field called "jr_phone" insert the code below inside your listing  theme file "detail.thtml"

Code:
<script type="text/javascript">
            function showPhoneNo(obj){
                var phoneNo = '<?php echo $CustomFields->field('jr_phone',$listing,false,false); ?>';
                var par = obj.parentNode;
                par.removeChild(obj);
                par.appendChild(document.createTextNode(phoneNo));
            }
</script>

2) Now add the code below inside Advanced Parameters of your Jreviews phone field:

Code:
<a rel="noindex, nofollow" href="javascript:void(0);" onclick="showPhoneNo(this);return false;">Show phone number</a>

3) You done !

If you need to translate the link "Show phone number" because your site is in two or more language just replace the text with a language string like this:

Code:
<a rel="noindex, nofollow" href="javascript:void(0);" onclick="showPhoneNo(this);return false;"><?php __t("Show phone number");?></a>

The last step is to include this language string inside the standard Jreviews language file called "default.po" in each of your language folder you want use with his appropriate translation.

More infos about here: http://www.reviewsforjoomla.com/forum/index.php?topic=14363.0

Cheers
Logged
bhaa taha
Newbie
*
Offline Offline

Posts: 3


« Reply #1 on: June 20, 2012, 02:54:04 PM »

Hi,
when i add the translate string in .po files  its not working
i Cleared Cache in admin and in browser  and not working ?
Thanks

i need to use this in the Field Output right?
Code:
<a rel="noindex, nofollow" href="javascript:void(0);" onclick="showPhoneNo(this);return false;"><?php __t("Show phone number");?></a>
Logged
Alejandro
Global Moderator
Administrator
Hero Member
*
Offline Offline

Posts: 28359


« Reply #2 on: June 20, 2012, 04:02:14 PM »

You can't use <?php ?> tags in the output format of a field. This code is to be used in theme files directly.
Logged

http://www.reviewsforjoomla.com/testimonials Leave a testimonial for JReviews
bhaa taha
Newbie
*
Offline Offline

Posts: 3


« Reply #3 on: June 21, 2012, 08:15:48 AM »

Hi,
please can you explain how to do that ?
I added this directly in detail.thtml but i click there no phone number  
Code:
<a rel="noindex, nofollow" href="javascript:void(0);" onclick="showPhoneNo(this);return false;"><?php __t("Show phone number");?></a>

and when i add this code its give me the Numbers in the bottom of the page
Thanks
« Last Edit: June 21, 2012, 08:22:49 AM by bhaa taha » Logged
Alejandro
Global Moderator
Administrator
Hero Member
*
Offline Offline

Posts: 28359


« Reply #4 on: June 21, 2012, 08:43:07 AM »

I am not able to provide support for this hack, I was just trying to be helpful before. You also need to add the javascript code provided by the other user. Good luck.
Logged

http://www.reviewsforjoomla.com/testimonials Leave a testimonial for JReviews
mikkox
Hero Member
*****
Offline Offline

Posts: 265


« Reply #5 on: June 21, 2012, 11:21:37 AM »

I confirm this trick work... On my own detail.thtml page I use the following code:

Code:
<div class="fieldRow jr_telephone"><div class="fieldLabel"><?php echo $CustomFields->label('jr_telephone',$listing); ?></div><div class="fieldValue "><?php echo $CustomFields->field('jr_telephone',$listing); ?><a rel="noindex, nofollow" href="javascript:void(0);" onclick="showPhoneNo(this);return false;"><?php __t("Show phone number");?></a></div></div>

..and off course like Alejandro say, you must include the javascript provided. Try to put the javascript code as really first element like this:

Code:
/**********************************************************************************
 * EDIT HTML BELOW THIS LINE
 **********************************************************************************/
//prx($listing); // Listing array
//prx($editor_review); // Editor review array
//prx($reviews); // User reviews array
?>

<!-- HIDE PHONE -->
<script type="text/javascript">
            function showPhoneNo(obj){
                var phoneNo = '<?php echo $CustomFields->field('jr_telephone',$listing,false,false); ?>';
                var par = obj.parentNode;
                par.removeChild(obj);
                par.appendChild(document.createTextNode(phoneNo));
_gaq.push(['_trackEvent', 'Link', 'Click', 'Telephone']);
            }
</script>
<!-- HIDE PHONE -->
Logged
bhaa taha
Newbie
*
Offline Offline

Posts: 3


« Reply #6 on: June 22, 2012, 04:21:26 PM »

thanks its work very well but Show phone number in the js code its visible even if there no number but the Field itself is not and the Field label
and i have 3 Field for phone number if it can be done its well be perfect .
Thanks
Logged
mikkox
Hero Member
*****
Offline Offline

Posts: 265


« Reply #7 on: June 22, 2012, 06:31:07 PM »

yes the "show phone" link is always displayed because in my case all my listings are imported inside Jreviews and all business data contain phone number.

If you want display the "show phone" link only when the related "phone" field is filled, maybe you must try to use conditional like explained at the bottom (Custom Field conditionals) of this docs:

http://docs.reviewsforjoomla.com/?title=How_to_customize_the_layout_of_custom_fields_in_Theme_files
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!