Adding Facebook's Like buttons

Creating and modifying plugins.
paux
Regular
Posts: 15
Joined: Thu Mar 23, 2006 8:46 pm
Location: Austria
Contact:

Adding Facebook's Like buttons

Post by paux »

Hi!

I think there's no such functionality yet, so I tried to do it by myself. Adding an FB-Like for the whole blog via e.g. HTML nugget is easy, as the main URL of the blog is static. But I want to add it for every article.

As starting point I edited entries.tpl and added the <iframe> after {$entry.add_footer}. But I don't know the best way to get the {$entry.link} as full URL including the server name, other than {$serendipityBaseURL|@escape:url}{$entry.link|@escape:url}, because here two slashes collide like http://hostname//s9yurl - I don't know whether multiple slashes in URLs are allowed anyway and/or whether FB ignores those.

I tried to use {$entry.feed_entryLink} instead, but this seems to be available in the feed_*.tpl only.

Is there a way to get the full URL into the link?

Regards,
Stephan
$ cd /pub
$ more beer
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Adding Facebook's Like buttons

Post by Don Chambers »

Try {$entry.rdf_ident} for the url, and try {$entry.title|escape} for the entry title if you need it.
=Don=
paux
Regular
Posts: 15
Joined: Thu Mar 23, 2006 8:46 pm
Location: Austria
Contact:

Re: Adding Facebook's Like buttons

Post by paux »

Thanks, that seems to do it:

Code: Select all

<iframe
    src="http://www.facebook.com/plugins/like.php?href={$entry.rdf_ident|@escape:url|@escape:url}&show_faces=false&width=440"
    scrolling="no"
    frameborder="0"
    style="border:none; overflow:hidden; width:440px; height:30px;"
    allowTransparency="true">
</iframe>
I know, the URL's encoded twice, and there are &'s instead of just &'s, but that's just how FB-Like generates it (in my Firefox). It seems to be right that way, but I haven't yet liked one of my posts. :)

Thanks!
Stephan
$ cd /pub
$ more beer
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Adding Facebook's Like buttons

Post by garvinhicking »

Hi!

Also, check out the serendipity_event_findmore plugin, it already has the FB like button.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
paux
Regular
Posts: 15
Joined: Thu Mar 23, 2006 8:46 pm
Location: Austria
Contact:

Re: Adding Facebook's Like buttons

Post by paux »

Ah, indeed, thanks for that!

However, with _event_twitter I already have more flexibility with Twitter and Identi.ca (short URLs, configurable tweet, identi.ca support). And I'm uncertain about what services I want to link to anyway.
$ cd /pub
$ more beer
Neut
Regular
Posts: 91
Joined: Sat Jun 17, 2006 7:51 pm
Location: NL, Earth
Contact:

Re: Adding Facebook's Like buttons

Post by Neut »

The Findmore plug-in works very well!
Question: it is now placed below the 'entryfooter'. I cannot find the code to change to have it displayed within the entryfooter (after author, date, comments). Any suggestions?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Adding Facebook's Like buttons

Post by garvinhicking »

Hi!

The plugin injects itself into the {$entry.plugin_display_dat} variable. You can move that to the place you want inside your entries.tpl template file!

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Neut
Regular
Posts: 91
Joined: Sat Jun 17, 2006 7:51 pm
Location: NL, Earth
Contact:

Re: Adding Facebook's Like buttons

Post by Neut »

Thanks Garv!
Who is General Failure, and why is he reading my disk?
Stosh
Regular
Posts: 75
Joined: Mon Oct 12, 2009 11:47 pm

Re: Adding Facebook's Like buttons

Post by Stosh »

Hi,

I also manually set up a facebook share button, with an eye to adding twitter, digg, and myspace in the future. I mainly went this route before looking for a plugin because, well, I'm a geek, and I like knowing how something works before I use it. :)

----------------------------
Update (of making manual buttons):

I have now placed six social buttons manually. I guessed as to which ones are the most important. If you know of any others that should be included please let me know.

Check them out at the site: Blog front page puts them at the top right of the page. They are placed to the left of the entry title when they are for the permalinked entry, e.g., Single Entry
----------------------------



Anyway, what I've learned from my experience setting up the facebook button is that there is a standard xml name-space for meta-information now (because, well, why use what you've already got if you can show everybody how smart you are by "inventing" something that implements the same functionality in a more complicated way).

This open graph name space can be used to tell facebook which image (from the page or elsewhere) to use, e.g.,

Code: Select all

<meta property="og:image" content="http://standoutpublishing.com/Res/Image/200x110ANN.jpg" />
These og properties can also specify the title, and (I think) the description text (though I haven't found the description property yet).

Facebook also claims to parse normal (existing) meta tags with similar names, but they are inconsistent with how and when they parse these.

Right now I just point a static meta property tag to a general graphic for the blog, which is the same for all entries (see code above). I'd like to be able to have an input facility that lets me provide defaults for these three properties, but that also allows me to override those defaults on a per-entry basis in the advanced options.

I looked at the HTML Meta plugin and the head information plugin but these don't seem to do what I need for the share buttons.

Any suggestions?

-djr
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Adding Facebook's Like buttons

Post by garvinhicking »

Hi!

What you can do is use the "Extended properties for entries" plugin. This one lets you add specific entryproperty tags to an entry, so you could define "og_meta1" or whatever, and access it inside your entries.tpl file as {$entry.properties.ep_og_meta1}.

Now the problem comes when you want to put them into your index.tpl template file, because there {$entry} is not available (because it's a nested array).

To have that you'd need to do some workaround looping:

Code: Select all

<html>
<head>
...
{if $is_single_entry} {* Only do this in single entry mode *}
{foreach from=$entries item="single_dategroup"} {* Loop all dategroups for a date (only 1) *}
  {foreach from=$single_dategroup.entries item="single_entry"} {* Loop all entries for a dategroup (only 1 as well) *}
     {if $single_entry.properties.ep_og_meta1} {*Check if the og_meta1 is set, and if yes, show it *}
       {$single_entry.properties.ep_og_meta1}
       {assign var="has_single_og" value="1"} {* Assign a temporary variable for later on *}
  {/foreach}
{/if}

{if $has_single_og != 1} {* Show a default, if no entry has assigned its own variable *}
<meta name="og:bla" value="blabla" />
{/if}
...
HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Stosh
Regular
Posts: 75
Joined: Mon Oct 12, 2009 11:47 pm

Re: Adding Facebook's Like buttons

Post by Stosh »

Garvin,

Thanks. I'll look into that when time permits.

-djr
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Adding Facebook's Like buttons

Post by schimanke »

Hi,

I am still experiencing some difficulties with the facebook like-button generated by the serendipity_event_findmore plugin. I was able to place it under each entry but there are still two problems.

The first problem seems to be related to the encoding of the URL. Facebook doesn't seem to like slashes, therefore the URL looks something like this: http://www.schimanke.com/index.php?%2Fa ... Cloud.html which leads to the homepage of my blog but not to the specified entry.

The other problem is related to the title of the entry. When I click the like-button, facebook should show the title of each entry but currently only shows the title of my blog (Flo's Weblog) instead.

You may try yourself here: http://www.schimanke.com

Are there any solutions to my problems?
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Adding Facebook's Like buttons

Post by schimanke »

Anybody?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Adding Facebook's Like buttons

Post by garvinhicking »

Hi!

The LIKE-Buttnon causes some grief because its hard to debug. The slashes in the url shouldn't really matter when they are properly encoded - on my tests a few months ago it worked. But Facebook often seems to change things without notice, so anything that once worked might no longer, and anything that works now, might not properly work in the future.

What I found was also important would be those fb-metatags in the head of the page. Sometimes those were required, sometimes facebook worked fine without those. It's hard to find a proper guide on this, since all sources seem to vary on what to use how exactly. :(

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Adding Facebook's Like buttons

Post by schimanke »

I might have found the cause of the problem playing around with my flattr and Twitter buttons. Up to now it is just a guess but could it be related to the question mark (?) in the URL? Here is what I have experienced with some of my buttons (flattr, Facebook, Twitter):

My URL looks for example like this: http://www.schimanke.com/index.php?/arc ... -3910.html

As you can see, there is always a question mark after "index.php". When I now flattr an article everything works fine, but the button count does not go up. Anyway, testing it with a static URL, leaving out the question mark, the correct number is shown.

Using a URL without question marks leads to a correct number. Using a URL with question mark leads to a zero in the count. To me it seems that the "count URL" gets cut when teh question marks occurs. For example when I use the Twitter button the correct link (for example http://www.schimanke.com/index.php?/arc ... -3910.html) is tweeted, but the tweet-count only looks for http://www.schimanke.com/index.php.

Since I can use a static URL without the question mark is there any way to leave it away? Is it needed for something?

@Garvin: Do you think this could also be the cause of my problem with the facebook button?
Post Reply