Facebook “Like” button for PierCMS sites
Every site should have a like button
Without going into too much detail and stirring the pot, I will just say that it’s a very good idea for your site to have a facebook “Like” button if you are looking to gain traffic by reference. So, if you agree, and you are running a PierCMS site, try this trick to include like button.
How to set it up
- Add a system component for html to your site. I called mine “facebookLike.”
- Into that component, add the following between script tags:
var url= (document.URL);
var base_url = url.split('?',1);
base_url = escape(base_url);
fblike="<iframe src=\"http://www.facebook.com/plugins/like.php?href="+base_url+"&layout=standard&show_faces=true&width=450&action=like&colorscheme=light&height=80\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:450px; height:80px;\" allowTransparency=\"true\"></iframe>";
document.write(fblike);
How to use it
Wherever you would like it to show up, just include:
/system/components/facebookLike
I put it in my environments right before the /system/components/contents tag on each page, so it automagically shows up everywhere.
What it’s doing
There is really nothing to this, and it can really be used on any site that doesn’t send over a pile of GET vars to render a page. But for those who are using PierCMS, it just:
- Grabs the current URL.
- Strips the extraneous session vars (anything after ‘?’). This is more important in PierCMS as it’s Seaside based, and retains a bunch of stuff in the url that can be left off for a cleaner url.
- Inserts a correctly formatted like button according to the FaceBook Like Button API .
So far, it works great. Let me know if you run into any troubles. Note that you can make several adjustments to the button, but it might be easier to just go to the like button page and get your iframe script, and substitute it for the fblike var above. Just make sure you note that there is a cleaned up (escaped) url hidden in there. base_url is the one you want to replace.
