The facebook like button is in. I know, you've been seeing it more and more around the web and now you want to implement it on your own website. I'll show you how to do just this using a little snippet of code that will allow you to add a dynamic Facebook "like" button to any page on your website!

First off, why would you want this? Let's say you have a blog and in the footer (or header... or sidebar) you'd like to have the facebook like button. Well, it really isn't very practical to have to insert this in the footer of your post everytime you create a new entry. Solution: let's leverage the power of PHP to make the Facebook like button dynamic!
Facebook Like Button PHP Code
<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo rawurlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&layout=standard&show_faces=false&width=275&action=like&colorscheme=dark&height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:275px; height:35px;" allowTransparency="true"></iframe>
Code Explanation
What the code above will do is allow you to insert a dynamic like button in a common place on your website and have that button's url change according to the page the visitor is on (hence why I say dynamic). For instance, on a WordPress site you could put the code in your sidebar.php file and the url to be 'liked' would be whatever page the visitor is on.
Extra Tips
If you don't want the url to change and only want the user to 'like' one url on your site (let's say the homepage for instance) then you could change the address to that static text. This is in fact how the Facebook like button creation tool works on their website.
Also: Don't forget the power of PHP and, if you're on the WordPress CMS then you can also leverage the built in functions like bloginfo('url'); and more! Simply replace
Hope you enjoy this snippet. Also, FYI... Facebook has changed 'become a fan' to just like... Questions? Leave a comment below or Contact DLOCC
Related posts:
- WordPress Heirarchical Sidebar Page Menus Let's say you want to show a hierarchical sidebar menu that displays a listing of current subpages. This is easy enough, but let's say that you have a top menu that shows all top-level pages. Once you click on a top level page from that menu it will take you there and in the sidebar [...]...
- WordPress List Subpages Even if On Subpage I'm building a new site and the navigation on it requires me to use a different bit of code for parent and child pages. I thought I'd share the code for those out there building a similar navigation. Here's a handy bit of code that you can use to display all subpages on a subpage. [...]...
- WordPress: If URL is Homepage then do this… Question: In WordPress how to I make sure the page loaded is the homepage URL and display some data if the standard WordPress Conditional Tags are not working for my theme?! Answer: Here's a quick snippet of code that will give you an option to do something if these WordPress basic conditional tags are not [...]...
- WordPress Loop: If Parent or Child of Page or Category The WordPress loop is extremely useful when developing customized WordPress solutions. One bit of code I've had to use often is one that will display a set of code if the page or post is a parent of child of a certain category. This is an easy way to display, output, or show data on [...]...
- Facebook High School Friend Phishing Have you recently gotten a friend request on Facebook from someone who you have no idea who they are but they have like 100 of your high school classmates as friends also? Well, chances are this 'person' is actually only taking your friends personal information as well as yours (if you accept their friend request). [...]...
-
http://IntranetSP Seb






