Adding Facebook "Like" Button

cozbaldwin
cozbaldwin's picture

Joined: 2008-07-15
Posts: 22
Posted: Thu, 2010-04-22 14:19

Since the launch of the new Facebook Like button yesterday, I've been trying with my feeble, little mind to get it working on my Gallery 2 pages. I don't know if I'm using the best method or not, but it's working... for Classic theme, at least.

Somewhere around halfway down your photo.tpl file, find:

Quote:
{else}
{g->text text="There is nothing to view for this item."}
{/if}
</div>

Now pop this in below it:

Quote:
<iframe src="http://www.facebook.com/plugins/like.php?href=http://www.YOUR_SITE_URL.com{g->url arg1="view=core.ShowItem" arg2="itemId=`$theme.item.id`"} &amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;font=trebuchet+ms&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:100px"></iframe>

Be sure to change www.YOUR_SITE_URL.com to whatever your site is. If it doesn't work, I apologize in advance for maybe not being able to help further... I feel lucky enough to have gotten this working for myself.

 
XCOM

Joined: 2002-12-30
Posts: 474
Posted: Thu, 2010-04-22 16:16

Hi!

After searching one hour how to add the current album url to my facebook like button, i found your posting with the {g->url arg1="view=core.ShowItem" arg2="itemId=`$theme.item.id`"} code :-)

Thank you!
________________________________________
[G2] Wallpaper-Fotogalerie | Gallery Blog | G3(dev) Barcelona Fotos

 
cozbaldwin
cozbaldwin's picture

Joined: 2008-07-15
Posts: 22
Posted: Thu, 2010-04-22 16:30

Sweet... glad I could help out other confused users.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Tue, 2010-04-27 19:18

Are you guys aware of this module for G2?
http://codex.gallery2.org/Gallery2:Modules:share

Yes, I know Like and Share are different, but didn't know if you were aware of that module.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
cozbaldwin
cozbaldwin's picture

Joined: 2008-07-15
Posts: 22
Posted: Tue, 2010-04-27 20:55

Yeah, I installed that but was disappointed with it. So I ended up just editing the photo.tpl to add in my ShareThis code.
I didn't even think until now that I can probably edit the Share module template by popping my ShareThis code into there... get a little more control out of it. So thanks for helping me take a 2nd look at the module and realize I could do that.

And yes, perhaps putting the Like button in there might work, too, as long as you're using the mini-sized version of it (so it fits in the sidebar).

 
miki64

Joined: 2009-07-18
Posts: 38
Posted: Thu, 2010-05-13 07:43

thanks, seems work good

visit my site
scattinviaggio.com

 
cozbaldwin
cozbaldwin's picture

Joined: 2008-07-15
Posts: 22
Posted: Thu, 2010-05-13 11:51

Ok - editing the Share Link module didnt work quite as well as I thought it would. It placed the ShareThis button at the top of the page. Since I cant begin to understand why the placement of the content changed when the content itself changed, I gave up on that idea quickly.

 
aweirdguy

Joined: 2007-09-14
Posts: 1
Posted: Sun, 2010-05-30 20:18

Thank you thank you, this is exactly what I was hoping to find. This would have taken me all day to figure out, if at all.

It worked perfectly and looks awesome with one minor modification: www.YOUR_SITE_URL.com/gallerypath/

as not all of us have our gallery installed in the root :-)

 
cozbaldwin
cozbaldwin's picture

Joined: 2008-07-15
Posts: 22
Posted: Wed, 2010-06-02 03:46
aweirdguy wrote:
Thank you thank you, this is exactly what I was hoping to find. This would have taken me all day to figure out, if at all.

It worked perfectly and looks awesome with one minor modification: www.YOUR_SITE_URL.com/gallerypath/

as not all of us have our gallery installed in the root :-)

Thats interesting, because I dont have mine installed on the root either. mine is in a subdirectory of /gallery/ but it still worked with what I originally posted.

 
cozbaldwin
cozbaldwin's picture

Joined: 2008-07-15
Posts: 22
Posted: Wed, 2010-06-09 04:37

Ok - That's a completely different beast with a completely different purpose than the new Facebook LIKE button, though.
I WISH Facebook would make their button as easy to install as ShareThis does.

 
brewster

Joined: 2010-07-12
Posts: 47
Posted: Mon, 2010-08-09 12:36

Had some issues with the code reading correctly (wouldn't accept forward slash between YOUR_SITE_URL.COM and GALLERY2 subdirectory for some reason and URL would run together). Took about 3 times (persistence pays off) and finally it worked.

Glad I saw aweirdguy's post - I tried code without directing to subdirectory and button kept erroring out. So in my case, it was necessary.

Overall, nice little feature.

Thanks cozbaldwin!

 
varun7pathak

Joined: 2011-02-11
Posts: 3
Posted: Fri, 2011-02-11 11:52

Hi Cozbaldwin,

Can you please provide the path of photo.tpl file in gallery context.

Thanks
Varun

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Fri, 2011-02-11 12:00

gallery2/themes/your theme/templates/photo.tpl

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
varun7pathak

Joined: 2011-02-11
Posts: 3
Posted: Mon, 2011-02-21 04:09

Thanks suprsidr and cozbaldwin :)

After successfully implementing the Like button i did a lil more research and extended the functionality.

Adding like button this way, does not show up the facebook feed. To do so, you need to add meta information to each of the gallery page. Once done It will not only show the link in news feed but also show the particular liked picture's thumbnail, title and description as well.

1)Begin by registering your url on fb through the following link.
http://developers.facebook.com/setup/
Once done you will have your appid. This is required in subsequent steps + it will also give u a link for fb analytics.

2)Open your theme.tpl file and add the following information in the header, just after the <head> tag
<meta property="og:title" content="{ $theme.item.title }" />
<meta property="og:type" content="album" />
<meta property="og:url" content='http://www.YOUR_SITE_URL.com/{g->url arg1="view=core.ShowItem" arg2="itemId=`$theme.item.id`"}' />
<meta property="og:site_name" content="Name of your site" />
<meta property="og:image" content='http://www.YOUR_SITE_URL.com/{g->url arg1="view=core.DownloadItem"}&g2_itemId={"`$theme.item.id`"}' />
<meta property="fb:app_id" content="YOUR APP ID" />
<meta property="og:description" content="{$theme.item.description}" />

This should do the desired. If you face any difficulty do let me know. I might be missing something here tht i dont remember.
You can see it work at: http://varunpathak.limewebs.com/photography/main.php
Hope it works for others as well :)

 
cozbaldwin
cozbaldwin's picture

Joined: 2008-07-15
Posts: 22
Posted: Mon, 2011-02-21 05:36

Thanks varun7pathak. Worked like a charm.

 
varun7pathak

Joined: 2011-02-11
Posts: 3
Posted: Mon, 2011-02-21 09:56

Am glad, it could be used.. :)

 
XCOM

Joined: 2002-12-30
Posts: 474
Posted: Tue, 2011-02-22 11:34

@varun7pathak

In your code you should change http://www.YOUR_SITE_URL.com/ to http://www.YOUR_SITE_URL.com

________________________________________
[G2] Wallpaper | Gallery Blog | G3(dev) Barcelona Fotos

 
eliz82

Joined: 2009-11-06
Posts: 71
Posted: Wed, 2011-03-16 09:34
varun7pathak wrote:
Adding like button this way, does not show up the facebook feed. To do so, you need to add meta information to each of the gallery page. Once done It will not only show the link in news feed but also show the particular liked picture's thumbnail, title and description as well.

thanks. it works ok, but I have a problem. I have the URL rewrite plugin activated.

it seems facebook do not create thumbnails for photos that have SPACE character in the file name. the space character is replaced by G2 with "+" character in the link name.

an example:
http://www.site.com/gallery/album/silviumatei/Mai+multe+imagini+noi/Mistret-13.JPG.html
for this kind of link the thumbnail is created in FB, even the album contain spaces (+ character)

http://www.site.com/gallery/album/silviumatei/Mai+multe+imagini+noi/Pescar+2.JPG.html
for this kind of link the thumbnail is not created in FB, because it has space (+ character) in the image name.

anyone have a similar problem ?
any ideas how to fix this ?

 
cozbaldwin
cozbaldwin's picture

Joined: 2008-07-15
Posts: 22
Posted: Wed, 2011-03-16 10:32

Eliz82, I can't assist with your problem and I've found one of my own.

Getting the notification of Eliz's new post, I decided to test my Like button just now and found it was not working. I removed the trailing slash as XCOM pointed out and it's sort of working. I can now see "Admin - Insights" added next to the button for me, but when I click LIKE, it gives me an error. It says the FB page for my image "could not be reached" and it gives me the URL it cannot reach. However, when I put that URL in the browser, it's a valid URL for the FB Page created for that image. I just have no idea why it can't reach it.

UPDATE: Ugh. So before I posted this, I decided to try a couple more things and somehow made things worse. I thought I put everything back to the way it was, but now, I can't even get the admin - insights to show up... and when clicking LIKE, it says "http://www.(my_URL).commain.php/?g2_itemId=%27Array.item.id%27. · Error"

Notice the end of the domain name is .commain.php (so there's a slash missing after .com)... also, theres an extra slash after the .php. But in my LIKE button code and header meta, I have no slash after the .com. What is going on?!

 
eliz82

Joined: 2009-11-06
Posts: 71
Posted: Wed, 2011-03-16 11:45
cozbaldwin wrote:
I decided to try a couple more things and somehow made things worse. I thought I put everything back to the way it was, but now, I can't even get the admin - insights to show up... and when clicking LIKE, it says "http://www.(my_URL).commain.php/?g2_itemId=%27Array.item.id%27. · Error"

have you removed the ` character from the code ?

 
cozbaldwin
cozbaldwin's picture

Joined: 2008-07-15
Posts: 22
Posted: Wed, 2011-03-16 22:15
eliz82 wrote:
cozbaldwin wrote:
I decided to try a couple more things and somehow made things worse. I thought I put everything back to the way it was, but now, I can't even get the admin - insights to show up... and when clicking LIKE, it says "http://www.(my_URL).commain.php/?g2_itemId=%27Array.item.id%27. · Error"

have you removed the ` character from the code ?

Yes, in fact, I replaced the ` with an ' ... but that's when things started getting funky. So I put back the ` and it's never been the same.

 
eliz82

Joined: 2009-11-06
Posts: 71
Posted: Thu, 2011-03-17 12:57

regarding my problem, i have try something different, to isolate the problem.
i have shared in my facebook direct links to JPG's. so there is no <head> meta information.

now i think is a rather facebook problem then a gallery problem (more specific URL rewrite plugin).
the problem is that Facebook do not reconize + character as space. if you replace the + with %20 , facebook will recognize the link and create thumbnail for that photo.

cozbaldwin wrote:
but that's when things started getting funky.

i know. that why i ask you.

 
cozbaldwin
cozbaldwin's picture

Joined: 2008-07-15
Posts: 22
Posted: Fri, 2011-03-18 06:40

This is outrageously frustrating for me. I have to show you.

For one item, it properly gives me the "Admin Page - Insights" links in the Like Box area (Which makes me think it's connecting fine), but when I click it, it gives me an error saying it can't connect to the page.
http://www.hiddeninthesand.com/gallery/v/fanart/Shadows.jpg.html

But for another item, it does NOT give me the "Admin Page - Insights" links and it properly handles the Like action. However, in my facebook feed, it doesn't show the thumbnail of the photo. Rather, it displays the Gallery2 chicklet from the bottom of the page. But at least it's working!
http://www.hiddeninthesand.com/gallery/v/fanart/tallyhall_southpark1.jpg.html

At first, I thought it was due to a space in the name, as Eliz82 was experiencing. But then I found these two examples that I'm providing you with links to so you can ensure I'm using the code properly. And as you can see, these two Gallery items do not have spaces in their names. So I am stumped. Facebook must have made some weird changes because this is not the only thing that's stopped working in recent weeks.

 
XCOM

Joined: 2002-12-30
Posts: 474
Posted: Fri, 2011-03-18 11:32

For the moment the like button on my http://mypics.at also stopped working. I am trying to add addthis function in the evening to my site.
________________________________________
Airpower11 | Gallery Blog | Barcelona

 
XCOM

Joined: 2002-12-30
Posts: 474
Posted: Sat, 2011-03-19 08:08
cozbaldwin wrote:
This is outrageously frustrating for me. I have to show you.

For one item, it properly gives me the "Admin Page - Insights" links in the Like Box area (Which makes me think it's connecting fine), but when I click it, it gives me an error saying it can't connect to the page.
http://www.hiddeninthesand.com/gallery/v/fanart/Shadows.jpg.html

The like button worked for me on your url. On my site it seems to be a problem with my facebook admin account for my fan site. Other users could use the like button ...
________________________________________
Airpower11 | Gallery Blog | Barcelona

 
cozbaldwin
cozbaldwin's picture

Joined: 2008-07-15
Posts: 22
Posted: Sat, 2011-03-19 09:15
XCOM wrote:
cozbaldwin wrote:
This is outrageously frustrating for me. I have to show you.

For one item, it properly gives me the "Admin Page - Insights" links in the Like Box area (Which makes me think it's connecting fine), but when I click it, it gives me an error saying it can't connect to the page.
http://www.hiddeninthesand.com/gallery/v/fanart/Shadows.jpg.html

The like button worked for me on your url. On my site it seems to be a problem with my facebook admin account for my fan site. Other users could use the like button ...
________________________________________
Airpower11 | Gallery Blog | Barcelona

Well isn't that just great. :/

 
ramzo

Joined: 2011-01-26
Posts: 7
Posted: Fri, 2011-04-22 12:51

Gentlemen!

I have another problem...

btw I used a different technique to get a Facebook Like link i.e.

1. Went to the Link http://developers.facebook.com/docs/reference/plugins/like/and then registered as per requirement
2. I got the code

Now when I paste it in template.pl or anywhere else...I am unable to place it in desired position. Either it gets to the top or extreme bottom.

Please can someone help me! I want it under the album page and as well as under each photo.

Thanks! Everyone...
ram

 
cozbaldwin
cozbaldwin's picture

Joined: 2008-07-15
Posts: 22
Posted: Fri, 2011-04-22 21:03
ramzo wrote:
Gentlemen!

I have another problem...

btw I used a different technique to get a Facebook Like link i.e.

1. Went to the Link http://developers.facebook.com/docs/reference/plugins/like/and then registered as per requirement
2. I got the code

Now when I paste it in template.pl or anywhere else...I am unable to place it in desired position. Either it gets to the top or extreme bottom.

Please can someone help me! I want it under the album page and as well as under each photo.

Thanks! Everyone...
ram

Yeah I think under the photo it's gotta be placed in the photo.tpl.
And I haven't tried it but I'd think it would work ok in the album.tpl too.... however the code might have to be changed.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Mon, 2011-11-21 05:20

Comments are now permitted for this topic.

 
eliz82

Joined: 2009-11-06
Posts: 71
Posted: Sun, 2011-12-04 16:29
eliz82 wrote:
it seems facebook do not create thumbnails for photos that have SPACE character in the file name. the space character is replaced by G2 with "+" character in the link name.

an example:
http://www.site.com/gallery/album/silviumatei/Mai+multe+imagini+noi/Mistret-13.JPG.html
for this kind of link the thumbnail is created in FB, even the album contain spaces (+ character)

http://www.site.com/gallery/album/silviumatei/Mai+multe+imagini+noi/Pescar+2.JPG.html
for this kind of link the thumbnail is not created in FB, because it has space (+ character) in the image name.

anyone have a similar problem ?
any ideas how to fix this ?

it seem there is a fix for this problem. i tested and it's working
http://gallery.menalto.com/node/96164#comment-359843

.
_____________
my G2 site

 
gabstero
gabstero's picture

Joined: 2010-01-06
Posts: 51
Posted: Fri, 2012-06-01 16:39

Hi all -

I am editing the theme.tpl using the provided code above for the FB like button on a Gallery 2.3.2

Looks like no matter what I do, my edits are not reflected on the live page. For instance the fb like code doesn't even appear in the page source!

am I doing something wrong?

thanks,
gabstero

 
XCOM

Joined: 2002-12-30
Posts: 474
Posted: Fri, 2012-06-01 17:30

@gabstero

Do you have deleted your cache? Or are you working with template files in the /local directory?

________________________________________
Wallpaper | Gallery Blog | Barcelona

 
gabstero
gabstero's picture

Joined: 2010-01-06
Posts: 51
Posted: Fri, 2012-06-01 17:46

thanks for the reply...

working with the gallery/themes/matrix/templates/theme.tpl and trying to insert the above quoted code in the header. Did that, but nothing happens. I discovered that if I change the theme to anything else but matrix then come back to matrix, then the page is updated (but no FB like button unfortunately on my photo pages).

So, in other words for each small edit on any tpl file I have to dump the cache?

thanks,
gabster

 
XCOM

Joined: 2002-12-30
Posts: 474
Posted: Fri, 2012-06-01 18:01

Go to Site Admin -> Performance and disable cache
________________________________________
Wallpaper | Gallery Blog | Barcelona

 
Dayo

Joined: 2005-11-04
Posts: 1642
Posted: Fri, 2012-06-29 10:58

An implementation of the fix referred to by eliz82 earlier in this thread has been provided by eliz82 and added to the unofficial G2.4.0 code base.
Testers and feedback required.

--
dakanji.com