dynamic facebook 'like' button

pjotr / 2011-05-16 06:15:31   

Hi,

i'm working on my portfilio website (in progress, check it here) and i would like to add a facebook 'like' button to every projects-page.

i was wondering if this button code can be dynamic. Now, for each page, i have to add the specific page-url to the button code manualy (where it says 'href=')

  1. <src="http://www.facebook.com/plugins/like.php?app_id=147570088644975&
  2. href=http%3A%2F%2Fwww.pjotr.be%2F2%2Findex.phpsend=false&layout=button_count&width=450&show_faces=false&action=like&colorscheme=light&font&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true">

I would like to add this button code somewhere to the php, so that it creates a like-button automatically for every new project i create in the projects section.

Is this possible? Or is the 'id' in the src-tag also url-specific?
If it is possible, what do i have to put in the 'href'-tag?

Greets,
Pieter

pernin / 2011-05-16 06:25:10   

The easy solution, unless it's page specific, you could have it in your menu area, the it would be permanently there. In that case I would suggest the index.php, somewhere about where the Built with Indexhibit text is

pjotr / 2011-05-16 06:36:38   

thanks for your reaction, pernin, although i do want to use it page-specific.

i would like it more to let people 'like' seperate projects. it communicates more directly about a specific project and lets me keep track of what the most popular projects are.

arsondpi / 2011-05-16 12:01:06   

I was looking for something similar today and I made this...

Paste the following to a code editor, save the file as plugin.facebook.php, in your plugins folder and then call the plugin in one of your exhibits just by typing:

  1. <plug:facebook />

The code:

----------------

  1. <?php if  defined'SITE'  exit'No direct script access allowed'
  2. function facebook
  3.     return "<iframe src='http://www.facebook.com/plugins/like.php?href="  BASEURL  ndxz_rewriter$go'url'  "' scrolling='no' frameborder='0' style='border:none; width:300px; height:80px'></iframe>"
  4. ?>

----------------

Of course you can add options etc - check the developers fb site..

Good luck.

Edited: Cleaned up the code bits...

arsondpi / 2011-05-16 12:12:46   

...oops the code is wrong. Url defaults to your base url so...

Vaska A / 2011-05-16 12:42:38   

Shoot...tried to clean it up but the forum is sucky. I hope this works...

  1. <plug:facebook />

The code:

----------------

  1. <?php if  defined'SITE'  exit'No direct script access allowed'
  2. function facebook
  3.     return "<iframe src='http://www.facebook.com/plugins/like.php?href="  BASEURL  ndxz_rewriter$go'url'  "' scrolling='no' frameborder='0' style='border:none; width:300px; height:80px'></iframe>"
Vaska A / 2011-05-16 12:43:39   

Argh...didn't know the forum wasn't parsing those little things...

I hope people get the idea...updates are coming to the forum but not today.

pjotr / 2011-05-16 14:59:38   

thanks for the help, arsondpi and vaska. I tried your suggestion, but it didn't work... I get the idea, but my knowledge of php-syntax is very weak.

I wonder if there is a dynamic name for 'the url of the current page' that i can call in the site index.php?

It would be handy for this too: to keep track of the usage of the facebook-like-button, and to have some control over what is published on the fb profile after someone clicks the button, it's necessary to add some facebook meta-tags (see this article from fb developers page).
It would be very handy to be able to let that meta-tags be filled out dynamically as well.

Something like this:

  1.     <meta property="og:title" content="<%obj_name%>"/>
  2.     <meta property="og:url" content="<%baseurl%>"/>
  3.     <meta property="og:image" content="<%baseurl%>/files/facebook_icon.gif"/>

But, in the 'og:url' property, 'baseurl' should be replaced by what i mentionded above: a dynamic referer to the actual url.

Also, it would be great to have the 'og:image'-property lead automatically to the images included on that projects page.

Probably this is typically something that seems peanuts for the php-illiterate, like me, although it is not simple at all from a developers perspective. But i think it would be very handy for a lot of indexhibit-users.

arsondpi / 2011-05-19 17:26:43   

This seems to work. It's not a plugin per se but it work for each page. Check the developers site for more options...

  1. <iframe src='http://www.facebook.com/plugins/like.php?href=<%baseurl%><%url%>&layout=button_count&colorscheme=dark' scrolling='no' frameborder='0' style='border:none; width:300px; height:80px'></iframe>
dghitis / 2011-05-20 20:08:26   

Hey guys, thanks for the great code on this.
Do you know of a way to place the like button at the bottom of each exhibit page under the content? I tried placing the iframe in my individual section but it shows up awkwardly at the top of the page and pushes my content over. Maybe placing this code somewhere in the exhibit plugin itself?

dannyghitis.com

dghitis / 2011-05-20 20:22:50   

Looks like I got the button position in the right spot by adding the code to the end of the container in the index.php.

I'd like to make it stay visible as the rest of the content scrolls by in the horizontal plugin. That way users can click it at any time instead of having to find it at the beginning. Any ideas?

dghitis / 2011-05-20 20:52:21   

Ouch, the button works fine until i get to my blog section. The new script doesn't allot the user to scroll down the blog...How can I exclude the one section from that script?

Rouser / 2011-10-09 15:08:51   

arsondpi

Could you specify,where exactly to place the code?In the index.php inside the "sample" or the "plugin" folder?
It would be very helpfull!!!

This thread has been closed, thank you.