You are here:  » facebook like button


facebook like button

Submitted by lunen on Tue, 2011-05-24 02:23 in

Is there away to add the facebook "like" button for each product? I think you need to pass the URL into the like code that I found on facebooks website.

<html>
    <head>
      <title>My Great Web page</title>
    </head>
    <body>
       <iframe src="http://www.facebook.com/plugins/like.php?href=YOUR_URL"
        scrolling="no" frameborder="0"
        style="border:none; width:450px; height:80px"><iframe>
    </body>
 </html>

Any ideas?

Submitted by support on Tue, 2011-05-24 07:58

Hi lunen,

Sure, you can normally get the page URL using

"http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]

So based on the example you found; you could simply paste the following into the end of your html/product.php:

<iframe src="http://www.facebook.com/plugins/like.php?href=<?php
print "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
?>" scrolling="no" frameborder="0" style="border:none; width:450px; height:80px"></iframe>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by lunen on Tue, 2011-05-24 15:56

David,

It works great. you missed the trailing </iframe>

so here's the code that works:

<iframe src="http://www.facebook.com/plugins/like.php?href=<?php
print "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
?>" scrolling="no" frameborder="0" style="border:none; width:450px; height:80px"></iframe>

Seems like a good feature to have.

Submitted by support on Tue, 2011-05-24 16:04

ooops - thanks! Corrected in the original post also.

Cheers,
David.
--
PriceTapestry.com

Submitted by alecs on Thu, 2011-06-02 15:09

WOW ! PERFECT !!!

Submitted by stevebi on Fri, 2016-01-22 11:03

Hello David,

I am trying to apply

href=<?php print "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; ?>
at Facebook developers URL section https://developers.facebook.com/docs/plugins/like-button but I am receiving an error

"The href entered is not recognized as a valid URL."

What am I applying wrongly in order to apply facebook like button at my website

Cheers

Steve

Submitted by support on Fri, 2016-01-22 11:41

Hi Steve,

You'd need to use the Like button code generator with a valid URL for your site, and then convert it to be dynamic using the PHP code afterwards, so for example;

href=http://www.example.com/merchants/

Once you have the code, then convert it to exactly what you had to make it a dynamic version however I would also add urlencoding e.g:

href=<?php print urlencode("http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]); ?>

Cheers,
David.
--
PriceTapestry.com

Submitted by stevebi on Fri, 2016-01-22 12:09

Thank you very much David!

Submitted by borisvel on Fri, 2016-01-29 13:42

Hi David,

could you format this iframe within default.css?

Thanks and kind regards, Boris

Submitted by support on Fri, 2016-01-29 13:52

Hi Boris,

Sure - from the <iframe ... > code above, in place of:

style="border:none; width:450px; height:80px"

use:

class='fb_like'

And then in your CSS, with the inline styles defined as a starting point;

.fb_like {
  border: none;
  width: 450px;
  height: 80px;
}

...and then anything else as required...

Cheers,
David.
--
PriceTapestry.com

Submitted by borisvel on Sat, 2016-01-30 09:39

Thanks a lot for your help David.