A couple of weeks ago I posted a walk through to add Facebook Comments to your blog along side Blogger comments. This gives visitors two commenting options and the opportunity to increase reader feedback by using the most popular social network on Earth. Just today one of my own readers requested a feature I had not even considered. He'd like to include a Facebook Comments count with each post on the main page. Sounds like a nice feature to me so I set out to implement this request.
Placement and Branding Comments
This tutorial assumes you're using my Facebook Comments tabbed setup already and is constructed to use show both counts side by side with the same tab icons each service provides. Bear in mind this modification nearly triples the width the comment count footer requires, so make sure to leave plenty of room on the footer line for best effect. Adjust the footer position for the comment count by editing the Blog widget under Design->Layout until you're satisfied this modification has sufficient space. Note: if you've customized your Blog template this likely will fail and you'll need to alter the code manually in Edit HTML mode.
Inserting the Facebook Comments Count in the Post Footer
First, open up Design->Edit HTML and check the Expand Widget Templates box. Next, hit Ctrl+F and search for post-comment-link. You will find something like this:
<span class='post-comment-link'><b:if cond='data:blog.pageType != "item"'>The above code conditionally displays a comment count in the footer only on the main page and search pages. We want to maintain this behavior, but add in icons and a Facebook Comments count by replacing this section of code with the below:
<b:if cond='data:blog.pageType != "static_page"'>
<b:if cond='data:post.allowComments'>
<a class='comment-link' expr:href='data:post.addCommentUrl' expr:onclick='data:post.addCommentOnclick'><b:if cond='data:post.numComments == 1'>1 <data:top.commentLabel/><b:else/><data:post.numComments/> <data:top.commentLabelPlural/></b:if></a>
</b:if>
</b:if>
</b:if>
</span>
Finishing Up
<span class='post-comment-link'>
<b:if cond='data:blog.pageType != "item"'>
<b:if cond='data:blog.pageType != "static_page"'>
<b:if cond='data:post.allowComments'>
<span class='fb-comments-count'><img class='comments-tab-icon' src='http://static.ak.fbcdn.net/rsrc.php/v1/yH/r/eIpbnVKI9lR.png'/>
<a class='comment-link' expr:href='data:post.addCommentUrl'><fb:comments-count expr:href='data:post.url'/> Comments</a></span>
<span class='blogger-comments-count'><img class='comments-tab-icon' src='http://www.blogger.com/img/icon_logo32.gif'/>
<a class='comment-link' expr:href='data:post.addCommentUrl' expr:onclick='data:post.addCommentOnclick'><b:if cond='data:post.numComments == 1'>1 <data:top.commentLabel/><b:else/><data:post.numComments/> <data:top.commentLabelPlural/></b:if></a></span>
</b:if>
</b:if>
</b:if>
</span>
Test your changes by Previewing them and checking for any errors. The counts should look similar to those on the tabs my Facebook Comments implementation provides. Once satisfied things are as they should be, Save Template. That's it, your main page posts should now include the comments count for Facebook in the footer. I hope you've found this tutorial helpful. Thanks for reading and good luck in your blogging.
30 comments :
Just incredible - exactly what I needed!
One problem though, and I'm sure its an issue with my template - the facebook comment number count doesn't seem to show everytime.
Take a look here: http://kaihorotimes.blogspot.com/ and you'll see what I mean.
Any ideas?
I had similar problems Mark. It seems to be on the Facebook end as near as I can tell. For instance, when I first added Facebook comments sometimes the code, taken from FB documentation btw, would return a 0 others nothing at all. As time passed, results have been more consistent.
I suggest you monitor things over the next few days. I anticipate you will see similar results to my own.
James
But how can i add the total number of comments? If i have 2 on blogger and 5 on facebook i would like to display "7 comments" in the footer. Can you help me do that?
@Bogdan, it could probably be done with javascript. It would be a bit of a hack to pull off, since it's reliant on a data point from Facebook. Basically, it requires an event listener to determine when FB returns it's count, then you'd have to extract the two counts, sum them and output this value with a label.
I'd have to look at the FB count and FB api a bit more to find a good way to do this. But it will have to wait some time as I'm busy with other work I'm afraid.
I may have to ditch this - It's coming up to two weeks and the display of the number of facebook comments is still unreliable and rarely shows, if at all.
This is in no way down to your code as I agree it's a facebook problem but their support is rubbish so will have to seek alternatives.
@Mark, Sorry to hear that. I wonder what the problem is, a timeout on the request is my guess.
Hi James - Well I've been playing around with the code and found that since I changed this line "script src='http://connect.facebook.net/en_US/all.js#xfbml=1'/" and changed the '1' for a '0' in this bit 'js#xfbml=1' everything seems to be working fine?!
I have no idea why or what consequences this change will have but it seems to work ok at the moment so will monitor.
Interesting, I'll have to do some investigating and see exactly what that is doing. I hadn't noticed that odd url on the documented script include.
sadly, somehow it is not working (facebook comments not counted) :(
Riuz maybe u do not have any comments to be counted :D
Thanks James.
On the footer page now both blogger as well as facebook comments count is visible. However, the facebook count doesnot show in the footer on the my main page (blogger does) it appears only in the footer of the post page.
You can check what I mean on the blog
http://shabdaurarth.blogspot.com/
I must confess your tips have been a great help and many of my friends also wanted it on their blog , I referred to your blog for help on this FB comments box code.
Thanks again.
It took awhile but now it shows on the main page. Sorry for the bother James.
Hi James,
After implementing your comments tabs and the comments counter, the links on either the facebook or the blogger comments links both take me to the default blogger post comments page, not the comments tab footer on the post. Any suggestions?
My blog: http://roadrunnerroads.blogspot.com
Thanks,
Michael
Never mind. Got it. Had to change the 'comments form placement' in settings|comments to 'embedded below post'.
-M
And here's a bit of weirdness that will maybe provide another clue to solving the fb count issue some of us are experiencing. My fb count isn't working at all (no number is displayed), but if I'm in 'Edit Template' and preview the page, it seems to work correctly.
@Michael, in my experience the counts failing to load are usually from a slow down on Facebook's end. The count retrieval is entirely up to their own JavaScript libraries and server fulfillment of the count request. I've just enclosed the necessary tags in what I think is a pleasing format for Blogger integration. Not always the case of course.
Looking at your blog though, everything looks correct. I've seen errors in the href supplied to the <fb> tags cause problems before. Yours look perfect and are working excellent, at least while I was taking a look.
James
James,
The fb count only began working after I employed Mark Burton's 'js#xfbml=0' trick.
Cheers,
M
Interesting, I'll have to take a few minutes to see what that's doing. My guess is it ends up defaulting to most recent. Not sure why that would be more stable though.
thanks james. i have been implementing your tricks on my blog and it is really helpful. i just click your ads to impress my appreciation towards your works. :D
Anyone having trouble with the comment counter today?
@Mark Burton
Hi, I am having the same problem as everyone else with the comment counter.
I changed the '1' to a '0', and it did work, but it created another problem as the Facebook comments box under the post completely disappeared. Not sure why.
hi, I am having the same problem as everyone else with the comment counter
tell to where to add this
"script src='http://connect.facebook.net/en_US/all.js#xfbml=1'/" where it is ?
i am really confused. pls help me ..
thanks . Sanjaya
nice box coment.. how can use this box coment to my blog..??
sorry my english is bad..
http://bb-repair.blogspot.com/
Thanks for the tips
I had implement the code but i have found some error.
It works nicely on the post page but it also shows on the static page of my blog.
Please visit http://www.gulmiresunga.com/p/submit-articles.html
How to remove that .
Please help me
is there anyway to show facebook comments below blogger post. so visitor do not need to open post.
im gonna try this one. thanks again!
hi james, nice post by the way.
any how, i want to ask, how can i reduce the margin between the icon and the text comment. like in my blog http://lhthebest12.blogspot.com .the icon and post comment doesn't really level and the margin is a bit far off. so I would like to make it neat and tidy. so people can easily comment. thanks!
Hi James, How do I get notified when someone comments via Facebook?
Hello,
The count only show on item pages but not on homepage. I even removed the conditional tags. I am currently constructing my new site ( hqgif.com ) and I want the comment count to appear on homepage as well.. pls help.. Thanks~
I changed this line "script src='http://connect.facebook.net/en_US/all.js#xfbml=0'/" and changed the '0' for a '1' in this bit 'js#xfbml=0'. it's not work.
Post a Comment