Facebook like button on current php page URL

How do you make a Facebook like button that can link to a template php page

http://www.mydomain.com/somephppage.php?post=1

A standard Facebook button code would be to like a specific URL (page) . In this case it’s a WebYep template page so I would not know what is going to be after the ?post=

How do you approach this problem? Or is there Facebook code that will grab the current page URL using javascript?

David Owen


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi David,
Normally I’d suggest creating a patch Action that sits on the page and updates the regular Softpress Facebook Actions with dynamic links. Annoyingly the Like Button Action runs so late in the publishing process (fwAfterEndHTML) that we can’t change any of the code that the Action creates unless we fork the Action and edit it ourselves. I’m reluctant to do that as I’d need to maintain an almost identical Action to the original.

You could do as you suggest and use JavaScript on the page to get the current URL and insert this into the Facebook like button when the page loads although as you are using PHP I’d be inclined to do all of this on the server. The following PHP should echo the current page URL for you;


<?php $pageURL = 'http';  if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}  $pageURL .= "://";  if ($_SERVER["SERVER_PORT"] != "80") {   $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];  } else {   $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; echo urlencode($pageURL); } ?>

Add this to a standard Facebook Like Button markup item and it becomes;


<iframe style="border:none; overflow:auto; width:221px; height:53px; background:#FFFFFF" src="http://www.facebook.com/plugins/like.php?locale=en_US&amp;href=<?php $pageURL = 'http';  if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}  $pageURL .= "://";  if ($_SERVER["SERVER_PORT"] != "80") {   $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];  } else {   $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; echo urlencode($pageURL); } ?>&amp;send=false&amp;layout=standard&amp;width=221&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font=lucida+grande&amp;height=53" scrolling="no" frameborder="0"></iframe>

Have a play around with the iframe width and height settings in the code and add this to your Freeway page as a markup item and you should be set.
Regards,
Tim.

On 29 Aug 2013, at 09:59, David Owen wrote:

How do you make a Facebook like button that can link to a template php page

http://www.mydomain.com/somephppage.php?post=1

A standard Facebook button code would be to like a specific URL (page) . In this case it’s a WebYep template page so I would not know what is going to be after the ?post=

How do you approach this problem? Or is there Facebook code that will grab the current page URL using javascript?


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Cheers!

David Owen

On 29 Aug 2013, at 12:30, Tim Plumb email@hidden wrote:

The following PHP should echo the current page URL for you;


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options