Facebook comment system websites is a common thing we see these days and to be candid, it’s a great way to engage your readers and keep your website interactive. I recently finished a music search engine but realized the comment system wasn’t that good. I figured out integrating Facebook comment would be a great way to better socialize it. I know all about adding Facebook comment to static web pages and I’ve integrated Facebook comment on Blogger blogs on several occasions but a dynamic PHP web pages? That was the first time and got me confused for a while. I added the comment alright but the problem I faced was that the same comment was appearing on all web pages and we’re talking of loads of pages here. Each search query on the site automatically generate a unique web page and it’s a really dynamic website.
Of course it’s easy to generate the code from Facebook developers page and implement it on your website but the problem is highlighted below. You will have the same comment on all web pages!
The only way to get rid of this problem is by generating the URL for each page automatically within the Facebook comment code. Wondering how I did this?
1. Be sure to first create a Facebook application that’s going to handle the comments.
2. Enter your domain in the space provided and be sure your website ends with a slash as shown below. Enter other details to create the application.
3. Now, at the head section of your website, add the code below:
<meta property="fb:admins" content="{YOUR_PROFILE_ID}"/>
You should replace YOUR_APP_ID with the App ID/API Key of that app you created earlier. You should see this on the application summary page.
You also replace YOUR_PROFILE_ID with your personal profile ID. This lets you moderate the comment. If you already have a facebook username and don’t know how to retrieve your profile ID, check this post.
That’s done, right? Now let’s move on to the next step.
4. Now, just after the opening <body> tag, paste the code below:
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=YOUR_APP_ID";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
5. This is the last part that’s a bit tricky. Remember we’re implementing the Facebook comment box on a PHP website with dynamic pages, right? The code we’re going to use next is what displays the comment box but it needs a URL to work. If you specify the href parameter as www.yoursite.com, the same comment will be shown on all pages but in this tutorial, we’re going to automatically generate the URL of each page within the Facebook comment box so each dynamic page has unique comments. Where ever you want to comment box to appear in the body of your website, paste this code:
$currentlink = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
echo "<fb:comments href='$currentlink' num_posts='10' width='570'></fb:comments>";
?>
10 represents the number of comments shown and 570 is the comment box width. You can adjust these if you want.
Like I said, this is strictly for PHP based websites. The comment box shown on each page is unique and you can see this on MP3Smoke.com as I had to find a way to make it work and it finally did.
The last part of the code whic is originally in HTML format was converted to PHP and $currentlink automatically generates the URL of the current page.


Twitter: enairablog
says:
Doncaprio, this is a nice tips for website exposure. I love your mp3smoke
Thanks for dropping by, Dona!
This got me so confused till I got here. Thanks for this post. Finally got the comment thingy working on a client’s site
Keep this going please, great job!
paisajes de tenerife recently posted..paisajes de tenerife
Twitter: NaijaWhistle
says:
Omo u de try abeg. Bigups Don.
Thanks for the compliment!
thanks , great article
Thanks for this. Facebook comment box is really important but many bloggers overlook this.
Twitter: johnhaines2011
says:
Superb! This fixed the problem I was getting working with WordPress!
Great! But you could’ve used a plugin to install it. It’s all good though.
Thanks so much! I was looking for something to add to my website, a music search engine just like yours.
It work liked a charm and i have implented this on all my video pages!
Thanks again!
Hey Don, thanks for this – helped me a LOT!
Is there any way to show all latest comments wrapped up as one list?
I’m not really sure… I’ve never thought about it actually. Glad you found the post useful though.
How to make comment box work unique but with restricted amount of url parameters?
Restricted amount of URL parameters? I didn’t really get that.
Hi Don, thanks for the tutorial, really needed an alternative to my crappy comment box which wasn’t really functioning. Early test shows this works, however is there a way to remove the link beside the comment box? Beside the comment box, there’ll always be a URL corresponding to the link they are at now. Is there a way to hide or remove it so that it wont be visible? Thanks
I really don’t think there should be any such link. Can I please take a look at it? Maybe a page you implemented it on?
Hi,
I think I’ve solved the issue. I simply moved one line of PHP coding to the top of the page and the link disappeared. Thanks a lot on this tutorial though.
MAn thank you a lot From Brazil….. Portuguese posts didn t explain nothing about this…. Thank uuuuu
you’re much welcom, Vinicius. Glad you found it useful.
Wow its works
thanks dude
What about implementing the facebook meta tags (meta property=”og:img: content=”your url to image here”), etc., for the send and like buttons on dynamic websites? Making sure that each page shows the image, description that matches the content on each page?
This is very great totorial Thank alot !
Twitter: era1989reme
says:
Great post ! it got me the fair bit of stuff which I kept looking for, in the past.
Thanks !