Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Mick. on July 20, 2010, 01:24:31 PM

Title: [TIP] Facebook Share Button
Post by: Mick. on July 20, 2010, 01:24:31 PM
Very simple to implement.

Open:
Themes/default/Display.template.php

Find:
Code: [Select]
// Maybe they want to report this post to the moderator(s)?
Add before:
Code: [Select]
                      if ($message['id'] == $context['topic_first_message'])
                            echo '<br /><br /><a name="fb_share" type="box_count" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script><br /><br />';
                            };
Title: Re: [TIP] Facebook Share Button
Post by: DoctorMalboro on July 20, 2010, 10:04:15 PM
Both versions?

Wow... i remember that if sentence for my first mod... :P
Title: Re: [TIP] Facebook Share Button
Post by: Mick. on July 20, 2010, 10:44:12 PM
Both versions?

Wow... i remember that if sentence for my first mod... :P

What both versions?  Nevermind.    Yeah, RC3
Title: Re: [TIP] Facebook Share Button
Post by: rakicko on August 13, 2010, 07:42:05 PM
where to put share image?
Title: Re: [TIP] Facebook Share Button
Post by: Masterd on August 14, 2010, 02:09:45 PM
You don't need any image.
Title: Re: [TIP] Facebook Share Button
Post by: lastnico on August 16, 2010, 10:11:46 AM
If you can, try to split up the thing in two parts:

Themes/default/Display.template.php
Code: [Select]
                      if ($message['id'] == $context['first_message']) {
                            echo '<br /><br /><a name="fb_share" type="box_count" href="http://www.facebook.com/sharer.php">Share</a><br /><br />';
                            };

And put this in the footer
Code: [Select]
              echo '<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>';

It will increase page loading speed time (a little bit).

See http://developer.yahoo.com/performance/rules.html#js_bottom for more info.
Title: Re: [TIP] Facebook Share Button
Post by: jekwumoore on August 22, 2010, 12:37:16 PM
nice job!
Title: Re: [TIP] Facebook Share Button
Post by: rngrdanny22 on August 30, 2010, 01:13:54 PM
Great job! I have a quick question... is there anyway to code it to where it only shows on the first message on the first page?

Currently, it is showing on the first message of every page within a topic. I only want it to show on the very first post in the topic.

Thanks!
Title: Re: [TIP] Facebook Share Button
Post by: lucas-ruroken on August 31, 2010, 12:52:34 PM
Good tip ;)
Title: Re: [TIP] Facebook Share Button
Post by: KensonPlays on September 06, 2010, 03:12:28 AM
Lastnico's suggestion makes sense...
Title: Re: [TIP] Facebook Share Button
Post by: L'AltroWeb on September 13, 2010, 09:23:43 AM
This code is for every first post in every page.
Is there any way to show only in first topics post (only for page 1)?
Title: Re: [TIP] Facebook Share Button
Post by: Dharshan on September 13, 2010, 09:57:59 AM
nice. thanks...
Title: Re: [TIP] Facebook Share Button
Post by: wcharlot on September 14, 2010, 12:24:41 AM
this is really a cool FAcebook share that I can also use.

Thanks  8) 8) 8)
Title: Re: [TIP] Facebook Share Button
Post by: SEOAUS on September 15, 2010, 01:24:56 AM
Good tips thanks for sharing this it will help me a lot. Keep sharing! Thanks!

EDIT: Linked removed
Title: Re: [TIP] Facebook Share Button
Post by: Herr_Inoddorell on September 23, 2010, 10:28:49 PM
This code is for every first post in every page.
Is there any way to show only in first topics post (only for page 1)?

Use this variable:

if ($message['id'] == $context['topic_first_message'])


BTW, this is for any version. I use it in 1.1.11

Thanks for share!
Title: Re: [TIP] Facebook Share Button
Post by: lucas-ruroken on September 24, 2010, 01:13:31 AM
Use this variable:

if ($message['id'] == $context['topic_first_message'])


BTW, this is for any version. I use it in 1.1.11

Thanks for share!

Better than that:
global $topicinfo;
if ($message['id'] == $topicinfo['id_first_msg'])

;)


because if you use "if ($message['id'] == $context['topic_first_message']) and you go to the second page... the button appears in the first post of that page :P
Title: Re: [TIP] Facebook Share Button
Post by: Herr_Inoddorell on September 24, 2010, 05:32:53 PM
Use this variable:

if ($message['id'] == $context['topic_first_message'])


BTW, this is for any version. I use it in 1.1.11

Thanks for share!

Better than that:
global $topicinfo;
if ($message['id'] == $topicinfo['id_first_msg'])

;)


because if you use "if ($message['id'] == $context['topic_first_message']) and you go to the second page... the button appears in the first post of that page :P

Really? I tested it, but it didn't happen to me, it only shows on the very first message with $context['topic_first_message']).

[spanish mode on]qué raro es hablarte en inglés haha  ;D[/spanish mode off]
Title: Re: [TIP] Facebook Share Button
Post by: lucas-ruroken on September 25, 2010, 01:50:21 AM
yeah, the english is very hard to me :p

You need add the global $topicinfo.....

$context['topic_first_message']) is for the first message in every page... but $topicinfo['id_first_msg'] is for the first post.


Title: Re: [TIP] Facebook Share Button
Post by: Herr_Inoddorell on September 25, 2010, 07:45:40 AM
yeah, the english is very hard to me :p

You need add the global $topicinfo.....

$context['topic_first_message']) is for the first message in every page... but $topicinfo['id_first_msg'] is for the first post.




Fine, but in my case it didn't happen that way, it only shows in the opening post of a topic, instead of the first post of a new page. It works for me at least :P, however, it's good to know another way, so I can learn much more :P.
Title: Re: [TIP] Facebook Share Button
Post by: lucas-ruroken on September 25, 2010, 12:17:09 PM
of course 8) :P
Title: Re: [TIP] Facebook Share Button
Post by: searchgr on September 25, 2010, 02:01:52 PM
Can i add this code to smf 2.0 ?
Title: Re: [TIP] Facebook Share Button
Post by: lucas-ruroken on September 25, 2010, 06:45:47 PM
this code is for smf2 ;)
Title: Re: [TIP] Facebook Share Button
Post by: searchgr on September 26, 2010, 01:34:41 AM
sorry, i meant the smf 2 RC2.
Title: Re: [TIP] Facebook Share Button
Post by: lucas-ruroken on September 26, 2010, 01:53:34 AM
sorry, i meant the smf 2 RC2.

Yeah! It works! ;D
Title: Re: [TIP] Facebook Share Button
Post by: searchgr on September 27, 2010, 01:45:53 AM
If you can, try to split up the thing in two parts:

Themes/default/Display.template.php
Code: [Select]
                      if ($message['id'] == $context['first_message']) {
                            echo '<br /><br /><a name="fb_share" type="box_count" href="http://www.facebook.com/sharer.php">Share</a><br /><br />';
                            };

And put this in the footer
Code: [Select]
              echo '<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>';

It will increase page loading speed time (a little bit).

See http://developer.yahoo.com/performance/rules.html#js_bottom for more info.

Where in the footer? Can you specify please?
Title: Re: [TIP] Facebook Share Button
Post by: searchgr on September 27, 2010, 01:55:16 AM
I have added the code and the facebook shows as a title: An Error Has Occurred!
Title: Re: [TIP] Facebook Share Button
Post by: Diomet on October 10, 2010, 05:58:59 AM
What is the code for "Share" button to appear on every message?
Title: Re: [TIP] Facebook Share Button
Post by: Masterd on November 26, 2010, 01:55:23 PM
Code: [Select]
                            echo '<br /><br /><a name="fb_share" type="box_count" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script><br /><br />';
Title: Re: [TIP] Facebook Share Button
Post by: kavasa on May 09, 2011, 07:03:58 PM
what about smf1.1.13? :-[
Title: Re: [TIP] Facebook Share Button
Post by: sunehrigal on May 09, 2011, 08:43:06 PM
Thanks it will really help me to track some traffic from facebook.. Keep sharing such informative and productive stuff.
Title: Re: [TIP] Facebook Share Button
Post by: metalmaragato on July 15, 2011, 01:38:21 AM
it work for SMF 1.1.14 and work fine with the Google +1 Topics MOD

Google +1 Topics code
Code: [Select]
// Start Google +1 Mod smfhacks.com
if ($message['id'] == $context['topic_first_message'] )
{
echo '<div style="float: left"><g:plusone href="' . $scripturl . '?topic=' . $context['current_topic'] . '" size="small"></g:plusone>
<script type="text/javascript" src="http://apis.google.com/js/plusone.js"></script></div>';
}
// End Google Plus +1 Mod smfhacks.com

This tip with some changes change the button for button_count
Code: [Select]
// Start Facebook share
if ($message['id'] == $context['topic_first_message'] )
{
        echo '<div style="float: left"><a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script></div>';
                            }
// End Facebook share

(http://imageplay.net/img/m7Gbd213098/2011_07_15_023536.jpg)

(http://imageplay.net/img/m7Gbd213099/2011_07_15_023720.jpg)
Title: Re: [TIP] Facebook Share Button
Post by: PLAYBOY on July 15, 2011, 01:43:39 AM
It think it would be a helpful mod for ones who dont like to do manual changes.
Title: Re: [TIP] Facebook Share Button
Post by: ~Dragon~ on July 15, 2011, 07:00:05 AM
it is easy tutorial trick! code!

Thank you so much information!
Title: Re: [TIP] Facebook Share Button
Post by: marci_n on July 22, 2011, 05:43:45 PM

This tip with some changes change the button for button_count
Code: [Select]
// Start Facebook share
if ($message['id'] == $context['topic_first_message'] )
{
        echo '<div style="float: left"><a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script></div>';
                            }
// End Facebook share

(http://imageplay.net/img/m7Gbd213098/2011_07_15_023536.jpg)

(http://imageplay.net/img/m7Gbd213099/2011_07_15_023720.jpg)


It's working but... when I click on share button facebook doesn't have the forum default thumbnails. Ive got "Choose a thumbnail" on the windows popup and there is forum logo but also avatars from users profile discussing in that shared topics. Any idea?
Title: Re: [TIP] Facebook Share Button
Post by: 8hoursale on July 23, 2011, 06:15:49 PM
I know this is an old topic, but hopefully someone can help me. I just tired to copy this this code:

Code: [Select]
if ($message['id'] == $context['topic_first_message'])
                            echo '<br /><br /><a name="fb_share" type="box_count" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script><br /><br />';};


and put it right before:

Code: [Select]
// Maybe they want to report this post to the moderator(s)?

received an error that said.

Code: [Select]
The file you tried to save generated the following error:
Parse error: syntax error, unexpected '}' in Display.template.php on line 676

I'm using SMF 1.1

I'd appreciate any help.

Thanks!
Title: Re: [TIP] Facebook Share Button
Post by: juliegreen on June 30, 2012, 09:00:11 AM
is that code working for current smf version? SMF 2.0.2.
Title: Re: [TIP] Facebook Share Button
Post by: Mick. on June 30, 2012, 09:28:37 AM
is that code working for current smf version? SMF 2.0.2.
Yes.
Title: Re: [TIP] Facebook Share Button
Post by: gerzok on July 27, 2012, 07:49:54 PM
this is like the facebook "like" button?  :-\
Title: Re: [TIP] Facebook Share Button
Post by: goldysaini on August 29, 2012, 01:08:01 AM
 this is really a cool Facebook share this it will help me a lot. Keep sharing! Thanks!
Title: Re: [TIP] Facebook Share Button
Post by: PLAYBOY on August 29, 2012, 01:24:59 AM
It think it would be a helpful mod for ones who dont like to do manual changes.

There is still not a mod to do this right?
Title: Re: [TIP] Facebook Share Button
Post by: adamgilchrist2012 on September 15, 2012, 07:59:59 AM
Thanks for the nice tips and I have tried it on my personal web page. It works.
Title: Re: [TIP] Facebook Share Button
Post by: thexan on September 17, 2012, 12:33:39 AM
good job. thank
Title: Re: [TIP] Facebook Share Button
Post by: wdh280 on September 23, 2012, 02:51:45 AM
it work for SMF 1.1.14 and work fine with the Google +1 Topics MOD

Google +1 Topics code
Code: [Select]
// Start Google +1 Mod smfhacks.com
if ($message['id'] == $context['topic_first_message'] )
{
echo '<div style="float: left"><g:plusone href="' . $scripturl . '?topic=' . $context['current_topic'] . '" size="small"></g:plusone>
<script type="text/javascript" src="http://apis.google.com/js/plusone.js"></script></div>';
}
// End Google Plus +1 Mod smfhacks.com

This tip with some changes change the button for button_count
Code: [Select]
// Start Facebook share
if ($message['id'] == $context['topic_first_message'] )
{
        echo '<div style="float: left"><a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script></div>';
                            }
// End Facebook share

(http://imageplay.net/img/m7Gbd213098/2011_07_15_023536.jpg)

(http://imageplay.net/img/m7Gbd213099/2011_07_15_023720.jpg)
Doesn't work for me, when i share facebook share button it doesn't pull the thread id. It ends up looking like this www.example.com/forums/index.php/null
Title: Re: [TIP] Facebook Share Button
Post by: siammongkol on October 16, 2012, 04:39:09 PM
Good Tips
Title: Re: [TIP] Facebook Share Button
Post by: ViperGoy.CoM on October 30, 2012, 11:50:34 PM
Let's do it ^^ nice tutorial
Title: Re: [TIP] Facebook Share Button
Post by: PLAYBOY on November 09, 2012, 07:16:40 AM
How can we make it visible only to visitors?
It adds a lot to the load time if added to every post.
Title: Re: [TIP] Facebook Share Button
Post by: kikwan on November 09, 2012, 09:14:20 AM
Very thank ;D
Title: Re: [TIP] Facebook Share Button
Post by: nualchan on November 11, 2012, 10:17:42 PM
Nice tutorial thank you kha   ;)
Title: Re: [TIP] Facebook Share Button
Post by: PLAYBOY on November 12, 2012, 05:23:43 AM
1- How can we make it visible only to visitors?
2- How can we add a logo to the share post? Right now It adds the title and part of the message but there is no logo.
3- Is there anyway to make the count box smaller?
4- How to make this button "Not appear" in some posts/boards ?


5-
(http://imageplay.net/img/m7Gbd213099/2011_07_15_023720.jpg)

How come mine shows a very big count box? How can i remove the count?

(http://imageplay.net/img/tya22293064/Capture.jpg)
Title: Re: [TIP] Facebook Share Button
Post by: PLAYBOY on November 19, 2012, 05:31:30 AM
Can anybody help me please?
Title: Re: [TIP] Facebook Share Button
Post by: Xhoi on November 20, 2012, 10:32:16 AM
ill add this to my plugin im making, hoping ill publish it soon  :-\
Title: Re: [TIP] Facebook Share Button
Post by: PLAYBOY on November 20, 2012, 12:48:01 PM
Cool. Please let us know when done.
Title: Re: [TIP] Facebook Share Button
Post by: rafmak10 on November 24, 2012, 11:42:28 AM
Hi,
Do you have any idea ho to change smf code to share topic on facebook not only as a text but text with pictures?
I have thise problem becouse if image is as a attachment I cant share topic with image :(

Best
Title: Re: [TIP] Facebook Share Button
Post by: Mick. on November 26, 2012, 07:54:42 PM
It think it would be a helpful mod for ones who dont like to do manual changes.

There is still not a mod to do this right?
i think someone made a mod
Title: Re: [TIP] Facebook Share Button
Post by: PLAYBOY on November 27, 2012, 01:07:25 AM
It think it would be a helpful mod for ones who dont like to do manual changes.

There is still not a mod to do this right?
i think someone made a mod

Can you give the link or the name of the mod?
Title: Re: [TIP] Facebook Share Button
Post by: winsoft on November 28, 2012, 04:21:55 PM
unfortunately it's not working anymore. Facebook forcing us to use like instead share for some reasons.
Title: Re: [TIP] Facebook Share Button
Post by: PLAYBOY on November 28, 2012, 04:51:08 PM
unfortunately it's not working anymore. Facebook forcing us to use like instead share for some reasons.

It works on my site. FShare is pretty good. But it needs some repair and improvements.


I know there is something like
"Like button but when you click also a comment box popsup so you add a comment there too."
Can we make this current like button like that?