Support Forum

Add Facebook Comments Using PHP Code

EK Edward Koon
Edward Koon
Member

Wondering if there is a way to add Facebook comments in a post? Have done this in the past by using a plugin and pasting it’s shortcode under a post.

Ditched the plugin and added fb-comments manually in my theme that works great. However i need to add this snippet in one of SimplePress template files to enable that function.

fbc.jpg

Poked around in the reboot theme files but not sure which file or where in the file to add this. 

22 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

Well – the correct template will be the Topic View (one in the Desktop folder and one in the Mobile folder).

But where exactly do you want to place this so I can be more precise?

Does it work by listening for the class (fb-comments)?

Oh – and you will have to change the href argument as well  but I can tell you what to use when I understand the location better.

EK Edward Koon
Edward Koon
Member

It should be inserted right after the first post in the text area.  

It pulls a comment app from Facebook allowing fb members to comment and optionally post their comment to their fb profile with a link to visit the topic. 

I have it just above my blog post comments so either may be commented on. 

YS Yellow Swordfish
Yellow Swordfish
Member

Let’s try this – although please remember I can not test this so anything could happen! Find the line of code in the topic view template(s) that corresponds to:

if (sp_has_posts()) : while (sp_loop_posts()) : sp_the_post();

and immediately after that and before the comment about starting the post section add the new bit in the following code:

if (sp_has_posts()) : while (sp_loop_posts()) : sp_the_post();
if ($spThisPost->post_index > 1) {
    echo ('<div class="fb-comments" data-href="'.$spThisTopic->topic_permalink.'" data-width="100%" data-numposts="10" data-order-by="social" data-colorscheme="light"></div>');
}

see of that works for you…

(Just in case – although I am sure you know – use the ‘Raw Code’ button and copy the code from the popup window.)

EK Edward Koon
Edward Koon
Member

Hi Andy, nope that didn’t work.. Though i did see a big white space between several existing posts.

Assuming the ideal position would be in the 1st post content immediately after the text. That way anyone wanting to comment using their Facebook act could do so only in the 1st post. Other posts to the thread would be using the forum itself.

Probably a good idea for a SP plugin to add this functionality. Just need this snippete added to the head section.

fb-head.jpg

Thanks again for your help.. wink

YS Yellow Swordfish
Yellow Swordfish
Member

So are you saying that supporting javascript is not being loaded by this plugin? Is that because the forum uses a page and the plugin only applies the script to WP posts?

Getting this into the header is no real problem but it still doesn’t look to me like that is enough. There must be another component to this I would have thought.

EK Edward Koon
Edward Koon
Member

All that is needed is those two snoppets, and creating the app on Facebook developers site. The app is connected to the sites domain. Don’t matter if it’s a post or page, just have to pull the post url. That could a problem with sp since it’s not a wordpress standard permalink. 

YS Yellow Swordfish
Yellow Swordfish
Member

There should be no problem with the permalink – it is WP consistent and we passed it in the code I gave you yesterday.
How is that header code being put in place now?

YS Yellow Swordfish
Yellow Swordfish
Member

So it should be there for pages as well as posts. So no need to double it up. I still think there is something more. I don’t see how the code from yesterday matches up with the code in your header…

EK Edward Koon
Edward Koon
Member

There are two code snippets. One for the header.php file and the other goes where the comments are supposed to appear. For my site i added the appear code just above my get comments line in single.php and page.php.

This website better explains the procedure.

YS Yellow Swordfish
Yellow Swordfish
Member

Any chance of a link to your forum page?

Actually to a topic page if possible,

EK Edward Koon
Edward Koon
Member

If y’all ever consider a plugin to add this functionality I’m thinking a shortcode added to the tinymce editor would be the cats ass. If someone creates a post and wants optional Facebook comments clicking a button would add a shortcode [fbcomments] at the bottom of the post being created.

During the election i gained a great deal of Facebook trial and error knowledge. Facebookers are hesitant to click a link. But if enticed via the post title, once on the page they were directed to will comment if Facebook comments is installed.

I found Facebookers wouldn’t comment using SP even if registration was not required. Thinking this would be a great tool for SP admins wanting to increase their forum use from Facebook members.

A plugin i used to run had the shortcode option [fbcomments] and that worked great putting it under the post text, but was not updated and caused amp pages errors.

My politics forum posts are out ranking WordPress blog posts. https://www.docsplace.org/forum/politics/

YS Yellow Swordfish
Yellow Swordfish
Member

Well just hold on… sorry to ay it is my code form yesterday that is wrong..

I told you to use:

if ($spThisPost->post_index > 1) {

and it SHOULD have been:

if ($spThisPost->post_index == 1) {

(That is two equal signs).

Apologies for that. Misunderstood the instructions. And we can certainly discuss the plugin idea….