MyBB Community Forums

Full Version: Facebook like button not showing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hallo.
I have tried to add a facebook like and share button below each treat, but the buttons will not show.

In Admin CP > Templates & Style > Templates > *your template* > Post Bit Templates > postbit I added {$post['button_facebook_like']} after {$post['button_rep']}.

In inc/functions_post.php I added eval("\$post['button_facebook_like'] = \"".$templates->get("postbit_facebook_like")."\";"); (now it look like this:
$post['userregdate'] = $lang->na;
		$post['postnum'] = $lang->na;
		$post['button_profile'] = '';
		$post['button_email'] = '';
		$post['button_www'] = '';
		$post['signature'] = '';
		$post['button_pm'] = '';
		$post['button_find'] = '';
		$post['onlinestatus'] = '';
		$post['replink'] = '';
		eval("\$post['user_details'] = \"".$templates->get("postbit_author_guest")."\";");
        eval("\$post['button_facebook_like'] = \"".$templates->get("postbit_facebook_like")."\";");

In Post Bit Templates I added a new template with the name postbit_facebook_like. In this template I added first
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="button_count" show_faces="false" width="450"></fb:like>

This one did not work, so I tried the different options I got from https://developers.facebook.com/docs/plu...ike-button.

Anyone who can help me out?
Not sure the need to create a whole custom template for it - can't you just add it to the postbit templates as is?
Jordan L. It's cleaner that way, and when a new update comes, it's more easy to just add 2 lines.

BUT I have tried to just copy/past from facebook.dev, with and without schript, (don't want the iframe version, so have not tried that), but with same result. Seems like something is blocking.
Hope you understand where I want those buttons, between rep button and replay button, does not matter witch side.

I'm not sure, but with the code from fb, will give likes to my site, and not to the threat. (but as I told, have tried, not working)
Add this to the headerinclude template.....

<div id="fb-root"></div>
<script>GET CODES FROM FB</script>

and add this to the postbit template...
<div class="fb-like" data-href="YOUR FB PAGE" data-layout="button" data-action="like" data-show-faces="true" data-share="false"></div>
mmadhankumar..did not work. The button is showing, but then the users will like the homepage and not the threat.
(2014-07-11, 12:12 PM)BaggerHD Wrote: [ -> ]mmadhankumar..did not work. The button is showing, but then the users will like the homepage and not the threat.

it will take the users to the FB page that you have entered in the "URL to Like" field in the page where you grabbed those codes... the like WILL NOT be added to the thread...
I know. that was not what I meant, I want that ppl can like a threat, not just the page I typed in. That way ppl can like more then one page, since there is multiple threats. And users at fb will then see the threat if/when they click on the liked page at fb.

I want users to like threat, don't have to like posts (answer's to threat)
Oh... sorry misunderstanding.... i am not sure whether the FB like works that way... i mean liking individual threads and not the homepage... but you can put a share button on the thread and ask users to share it on their fb...

for this you need to first grab a "fb share" image.. check fb developers page or google it.. upload it to your server..

then goto showthread template find {$newreply} and add above it

<div style="margin-top: 6px; padding-right: 0px 10px;" class="float_left">
<a title="Facebook" href="http://www.facebook.com/share.php?u={$mybb->settings['bburl']}/showthread.php?tid={$thread['tid']}" target="_blank"><img src="PATH TO FB SHARE ICON" alt="FB Share" />
</a></div>
Have seen that it is possible with wp. Have tried this plugin, but then there is not showing any buttons, but what I can see in the code, it should be possible (but I'm not a coding person)

<?php

if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$plugins->add_hook("postbit", "fblike_start");
$plugins->add_hook("showthread_start", "fblike_showthread_start");

function fblike_info()
{
	return array(
		"name"			=> "FBLike",
		"description"	=> "Displays Facebook like button",
		"website"		=> "http://mybbmodding.net",
		"author"		=> "Nayar",
		"authorsite"	=> "",
		"version"		=> "1.2.1",
		"compatibility" => "16*",
		"guid" 			=> "",
	);
}
function fblike_activate()
{
	global $db;
	$fblike_group = array(
		"gid" => "NULL",
		"name" => "fblike",
		"title" => "FBLike",
		"description" => "Displays facebook like buttons",
		"disporder" => "15",
		"isdefault" => "no",
	);
	$db->insert_query("settinggroups", $fblike_group);
	$gid = $db->insert_id();
	/*$fblike_setting_1 = array(
		"sid"			=> "NULL",
		"name"			=> "fblike1",
		"title"			=> "Enable/Disable fblike",
		"description"	=> "",
		"optionscode"	=> "onoff",
		"value"			=> '1',
		"disporder"		=> '1',
		"gid"			=> intval($gid),
	);*/
	$fblike_setting_2 = array(
		"sid"			=> "NULL",
		"name"			=> "fblike2",
		"title"			=> "Is MyBB SEO enabled",
		"description"	=> "",
		"optionscode"	=> "onoff",
		"value"			=> '1',
		"disporder"		=> '2',
		"gid"			=> intval($gid),
	);
	$fblike_setting_3 = array(
		"sid"			=> "NULL",
		"name"			=> "fblike3",
		"title"			=> "Show on All posts",
		"description"	=> "",
		"optionscode"	=> "onoff",
		"value"			=> '1',
		"disporder"		=> '3',
		"gid"			=> intval($gid),
	);
	$fblike_setting_8 = array(
		"sid"			=> "NULL",
		"name"			=> "fblike8",
		"title"			=> "Show a like button with faces above thread",
		"description"	=> "",
		"optionscode"	=> "onoff",
		"value"			=> '1',
		"disporder"		=> '4',
		"gid"			=> intval($gid),
	);
	$fblike_setting_9 = array(
		"sid"			=> "NULL",
		"name"			=> "fblike9",
		"title"			=> "Where to show like button in posts",
		"description"	=> "",
		"optionscode"	=> "radio
1 = Right
2 = Left",
		"value"			=> '1',
		"disporder"		=> '5',
		"gid"			=> intval($gid),
	);
	$fblike_setting_4 = array(
		"sid"			=> "NULL",
		"name"			=> "fblike4",
		"title"			=> "Like/Recommend",
		"description"	=> "",
		"optionscode"	=> "radio
1 = Like
2 = Recommend",
		"value"			=> 'like',
		"disporder"		=> '6',
		"gid"			=> intval($gid),
	);
	$fblike_setting_5 = array(
		"sid"			=> "NULL",
		"name"			=> "fblike5",
		"title"			=> "Light/Dark",
		"description"	=> "",
		"optionscode"	=> "radio
1 = Light
2 = Dark",
		"value"			=> '1',
		"disporder"		=> '7',
		"gid"			=> intval($gid),
	);
	$fblike_setting_7 = array(
		"sid"			=> "NULL",
		"name"			=> "fblike7",
		"title"			=> "Height",
		"description"	=> "",
		"optionscode"	=> "text",
		"value"			=> '20px',
		"disporder"		=> '8',
		"gid"			=> intval($gid),
	);
	$fblike_setting_6 = array(
		"sid"			=> "NULL",
		"name"			=> "fblike6",
		"title"			=> "Forum ID where NOT to display like button in posts",
		"description"	=> "Enter Forum ID separated with commas",
		"optionscode"	=> "text",
		"value"			=> '',
		"disporder"		=> '9',
		"gid"			=> intval($gid),
	);
	//$db->insert_query("settings", $fblike_setting_1);
	$db->insert_query("settings", $fblike_setting_2);
	$db->insert_query("settings", $fblike_setting_3);
	$db->insert_query("settings", $fblike_setting_4);
	$db->insert_query("settings", $fblike_setting_5);
	$db->insert_query("settings", $fblike_setting_6);
	$db->insert_query("settings", $fblike_setting_7);
	$db->insert_query("settings", $fblike_setting_8);
	$db->insert_query("settings", $fblike_setting_9);
	//$db->insert_query("settings", $fblike_setting_10);
	//$db->insert_query("settings", $fblike_setting_11);

}
function fblike_deactivate()
{
	global $db;
	$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='fblike'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='fblike1'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='fblike2'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='fblike3'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='fblike4'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='fblike5'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='fblike6'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='fblike7'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='fblike8'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='fblike9'");
	//$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='fblike10'");
	//$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='fblike11'");
}
function fblike_start($post)
{
	global $postcounter,$mybb,$tid;
	// Set button blank
	$fblike = '';
	
	$display = true;
	
	// Fetch forum id for which not to display button
	$lmao1 = explode(",",$mybb->settings['fblike6']);
	
	// I don't know how this works. Just copied it from another plugin. And yes, i really don't know PHP. LOL xD
	foreach($lmao1 as $lmao2)
	{
		// If current forum id doesn't match prohibited forum id
		if (trim($lmao2) == $post['fid'])
		{
			$display = false;
		}		
	}
	if ($display)
	{
			// Lets get started now. Yahooo!!!!!!
			// You want Like or Recommend ?
			If ($mybb->settings['fblike4'] == 1)
			{
				$rofl1 = "like";
				// and set the width
				$rofl3 = "80px";
			}
			Else
			{
				$rofl1 = "recommend";
				// Recommend button is wider so we set a wider width ;)
				$rofl3 = "125px";
			}
			
			// You, yes You! Are you dumb? I am talking and you just stare at me :@
			If ($mybb->settings['fblike5'] == 1)
			{
				// I will stay quiet now unless you say sorry. 
				$rofl2 = "light";
			}
			else
			{
				// Louder! I can't hear.
				$rofl2 = "dark";			
			}
			
			// Ok. Thats like a good kid. I forgive you.  
			// So now, we fetch the height the user set.
			$rofl4 = $mybb->settings['fblike7'];
			
			// First post is exceptional!!!
			if ($postcounter == "1")
			{
				 // We now generate the button. Liking it will like the thread's URL
				 // Ask if SEO is ON
				if ($mybb->settings['fblike2'] == 1)
				{
					$fblike = '<iframe src="http://www.facebook.com/plugins/like.php?href=' . $mybb->settings['bburl'] . '/thread-' . $tid . '.html&amp;layout=button_count&amp;show_faces=false&amp;width=450&amp;action='.$rofl1.'&amp;font=verdana&amp;colorscheme='.$rofl2.'&amp;height=20" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:'.$rofl3.'; height:'.$rofl4.';"></iframe>';
				}
				else
				{
					$fblike = '<iframe src="http://www.facebook.com/plugins/like.php?href=' . $mybb->settings['bburl'] . '/showthread.php?tid='.$tid.'&amp;layout=button_count&amp;show_faces=false&amp;width=450&amp;action='.$rofl1.'&amp;font=verdana&amp;colorscheme='.$rofl2.'&amp;height=20" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:'.$rofl3.'; height:'.$rofl4.';"></iframe>';
				}
			}
			
			// Other posts are now dealt.
			// But only if the user wants it. hehe
			elseif ($mybb->settings['fblike3'] == 1)
			{	
				// Generate button for individual posts
				// Ask if SEO is on again
				if ($mybb->settings['fblike2'] != 1)
				{
					$fblike = '<iframe src="http://www.facebook.com/plugins/like.php?href='.$mybb->settings['bburl'].'/showthread.php?pid='.$post['pid'].'&amp;layout=button_count&amp;show_faces=false&amp;width=450&amp;action='.$rofl1.'&amp;font=verdana&amp;colorscheme='.$rofl2.'&amp;height=20" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:'.$rofl3.'; height:'.$rofl4.';"></iframe>';
				}
				else
				{
					$fblike = '<iframe src="http://www.facebook.com/plugins/like.php?href=' . $mybb->settings['bburl'] . '/post-' . $post['pid'] . '.html&amp;layout=button_count&amp;show_faces=false&amp;width=450&amp;action='.$rofl1.'&amp;font=verdana&amp;colorscheme='.$rofl2.'&amp;height=20" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:'.$rofl3.'; height:'.$rofl4.';"></iframe>';
				}
			}
	}
	// Now, we display the button. *Firecrackers*
	// Ask where to display button
	if ($mybb->settings['fblike9'] == 1)
	{
		$post['button_delete_pm'] = $post['button_delete_pm'].$fblike;
	}
	else
	{
		$post['button_email'] = $fblike.$post['button_email'];
	}
}
function fblike_showthread_start()
{
	global $mybb,$templates,$rofl1,$rofl2,$thread;
	// Ask if display above post.
	// Fetch forum id for which not to display button
	$display = 1;
	$lmao1 = explode(",",$mybb->settings['fblike6']);
	
	// I don't know how this works. Just copied it from another plugin. And yes, i really don't know PHP. LOL xD
	foreach($lmao1 as $lmao2)
	{
		// If current forum id does matches prohibited forum id
		if (trim($lmao2) == $thread['fid'])
		{
			$display = 0;
		}
		
	}
	if ($mybb->settings['fblike8'] == 1 && $display == 1)
	{
		// You want Like or Recommend ?
		If ($mybb->settings['fblike4'] == 1)
		{
			$rofl1 = "like";
		}
		Else
		{
			$rofl1 = "recommend";
		}
		If ($mybb->settings['fblike5'] == 1)
			{
				// I will stay quiet now unless you say sorry. 
				$rofl2 = "light";
			}
			else
			{
				// Louder! I can't hear.
				$rofl2 = "dark";			
			}
		if ($mybb->settings['fblike2'] == 1)
		{
			// SEO On
			$templates->cache['showthread'] = str_replace('{$posts}','<iframe src="http://www.facebook.com/plugins/like.php?href={$mybb->settings[\'bburl\']}/thread-{$tid}.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action={$rofl1}&amp;colorscheme={$rofl2}&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:73px;" allowTransparency="true"></iframe>{$posts}',$templates->cache['showthread']);
		}
		else
		{
			// SEO Off
			global $tid;
			$templates->cache['showthread'] = str_replace('{$posts}','<iframe src="http://www.facebook.com/plugins/like.php?href={$mybb->settings[\'bburl\']}/showthread.php?tid={$tid}&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action={$rofl1}&amp;colorscheme={$rofl2}&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:73px;" allowTransparency="true"></iframe>{$posts}',$templates->cache['showthread']);
		}
	}
}
?>
Check whether this helps..... Add this to the headerinclude template.....

<div id="fb-root"></div>
<script>GET CODES FROM FB</script>

and add this to the postbit template...

<div class="fb-like" data-href="{$mybb->settings['bburl']}/showthread.php?tid={$tid}&pid={$post['pid']}" data-layout="button" data-action="like" data-show-faces="false" data-share="false"></div>
Pages: 1 2