I've got a bit of a problem with facebook comments box on my website. I can't figue out a way for it to link the comments to the url they are on. For example a fb comment to Post 1 on my site is shared between all of my post wich can be a bit misleading for the users. I post about hundred posts a day (pics mainly), there's no way I can make a new box for each and every one of them.
Here's the piece of code that's troubling me:
<div class="fb-comments" data-href="funshit.ru" data-num-posts="5" data-width="530" data-colorscheme="dark"></div>
If only there was a way to make it link to the current url the problem'd be solved.
Any help is appreciated m8s.
Because the CMS I was coding in didn't reliably return the current URL and leaving it blank or omitting it failed, I wrote the div tag in Javascript:
<script>
document.write("<div class='fb-comments' data-href='" + window.location.href + "' data-num-posts='2' data-width='400'></div>");
</script>
Of course, this will include the data in the query string but you should be able to exclude that if that's what you want.
You can omit data-href (or leave it blank) so current URL will be used.
Update:
As of Sep 2012 the method above is working only for first version of the Facebook Comments box.
To use newer version of Comments social plugin you will need to specify current URL explicitly.
This one seems to be foolproof and vastly simple:
// In the next line, you must grab the parent element of the div with class fb-comments.
var oComments = document.querySelector("#CONTAINER-OF-COMMENTS-BOX");
oComments.innerHTML = '<div class="fb-comments" data-href="http://www.whatever.com/" data-num-posts="NUMBER OF POSTS TO SHOW" data-width="WIDTH OF CONTENT"></div>';
FB.XFBML.parse(oComments);
You can alternatively select the parent element with jQuery like so:
var oComments = $(".fb-comments").parent().get(0);
Make sure to alter the data-href attribute of the fb-comments div to change the URL for which the comments are about. You should also adjust data-num-posts for the number of posts to show and data-width for the width of the content. That ought to do it!
Use check below script, which is working for me.
<script type='text/javascript'>
var postUrl = '<data:post.url/>';
document.write("<div class="fb-like" data-href='" + postUrl + "' data-layout="standard" data-action="recommend" data-show-faces="true" data-share="true"></div>");
</script>
Its give link of each post accordingly.
I am a blogger, I Used below script in my blog, which is working for me.
<script type='text/javascript'>
var postUrl = '<data:post.url/>';
document.write("<div class="fb-like" data-href='" + postUrl + "' data-layout="standard" data-action="recommend" data-show-faces="true" data-share="true"></div>");
</script>
Its give link of each post accordingly. It might help full for you also.
Related
I am looking for a way to integrate several Facebook Comment Boxes on one page, but with different comments. i have an image grid view and inserted in the lightbox overlays the code from the Facebook comment box generator. With an random number at the end of the URL i tried to fix it, but there comes the error:
Warning: https://URL/#2087943573 can not be opened.
Any ideas?
You just have to add an anchor to the absolute URL, like it is explained in another thread:
Multiple facebook comment boxes on a single page?
You can even test this in the plugin generator:
https://developers.facebook.com/docs/reference/plugins/comments/
...try changing "http://example.com" to "http://example.com#test" and you will see that some other people already commented on that one too.
edit: After a small chat, we found out that the problem might be with the https. So, maybe it just doesn´t work with SSL, i´ve also tried with another server and it only works with the http link.
Try to make "fake" pages for each article that you have with GET variable. For the example:
example.com?fb_share=article1, example.com?fb_share=article2, etc.
Then here you must put the URL:
<div class="fb-comments" data-href="http://example.com?fb_share=article1" data-numposts="5" data-colorscheme="light"></div>
and
<div class="fb-comments" data-href="http://example.com?fb_share=article2" data-numposts="5" data-colorscheme="light"></div>
You don't need to use these pages, but you need it because when someone commenting, the FB comment will be posted on the wall with backlink to your article and for data-href attribute.
By doing these code, it works for my site. Using $_SESSION while looping and echoing data from MySQL database.
<div id= "area_post">
<?php
$query= mysql_query("select * from promo_diskon");
$url_id=0;
while($data= mysql_fetch_assoc($query)){
$textpromo = nl2br($data['deskripsi']);
$_SESSION["url_id"]="http://localhost/xampp/kerjapraktik/promo_diskon.php?posting=".$url_id."";
echo
"<div id='posting'>
<div id='layer'><div class='judul'>".$data['judul']."</div><div class='tanggal'>".$data['tanggal']."</div>
<br/ ><br /><p id= 'deskripsi1' class='deskripsi1'>".$textpromo."</p></div>
<a href=''><img class= 'img-thumbnail' src= ".$data['url_foto']." width= '440px' alt=''></a>
</div>";
//echo '<div class="fb-comments" data-href="http://localhost/xampp/kerjapraktik/promo_diskon.php?posting="'.$url_id.'"" data-width="956" data-numposts="5" data-colorscheme="dark"></div>';
echo '<div class="fb-comments" data-href="'.$_SESSION["url_id"].'" data-width="956" data-numposts="5" data-colorscheme="dark"></div>';
$url_id++;
}
?>
</div>
I recently coded my own blog for a site im making. I want to use facebook to handle the comment on posts, so i integrated the plugin. I noticed something odd however. If i comment on one blog post, then go to a different one, my comment is on the other blog posts as well. How do i make it so each post has its own set of comments?
You have to set a different data-href attribute for each post. Here's an example of how I do it in Yii:
<div class="fb-comments" data-href="http://domain.com/post/view/<? echo $model->id; ?>" data-num-posts="4" data-width="695"></div>
The point is the data-href value has to be unique for each post.
Assuming you are using html5 comments box.
Refer to: https://developers.facebook.com/docs/reference/plugins/comments/
data-href="" // data href sets the url "object id" for the box, you need to use a dynamic system with php, or javascript or what ever language you coded in.
<div style="padding-left:5px; min-height:500px" class="fb-comments" data-href="'+newUrl+'" data-num-posts="20" data-width="380"></div>
"i use" EXAMPLE:
the following examples works for pages with dynamic urls
example.com?id=thisid&thisarticle=article-name
<div id="thecomments"></div>
<script>
function changeCommentsUrl(newUrl){
// should refresh fb comments plugin for the "newUrl" variable
document.getElementById('thecomments').innerHTML='';
parser=document.getElementById('thecomments');
parser.innerHTML='<div style="padding-left:5px; min-height:500px" class="fb-comments" data-href="'+newUrl+'" data-num-posts="20" data-width="380"></div>';
FB.XFBML.parse(parser);
}
var thisurl = document.write(document.URL);
changeCommentsUrl(thisurl);
</script>
You could simply place that kind of snippet in your footer :
<script>
$(".fb-comments").attr("data-href", window.location.href);
</script>
It does the job...
Currently I have 3 comment boxes on a single page. The page has three tabs that display different content, and each tab content has its own comment section, differing from the other two.
To make sure unique comments are loading for each tab, I am currently using something similar to:
<div class="fb-comments" data-href="http://webpage.com/index.html#tab1"
data-num-posts="2" data-width="470"></div>
<div class="fb-comments" data-href="http://webpage.com/index.html#tab2" ...
<div class="fb-comments" data-href="http://webpage.com/index.html#tab3" ...
This works in displaying the relevant content. However, when someone replies to one of these comments, the original commentor receives a link on their fb profile that appears as:
http://webpage.com/index.html?fb_comment_id=fbc_26547577547547_477747457_3745757457435737#4574575475
The problem is that this link the user is given does not show the relevant comment thread, or even the anchor based data-href comment box. Perhaps the end anchor is tripping up the display? If so, is there a paradigm for having different facebook comment boxes on a single page?
Thanks for any help solving this annoying issue.
I implemented something similar using this code
<div class="fb-comments" data-href="http://stabmail.com/study-groups-tutoring/#comm-enl" data-width="880" data-num-posts="20"></div>
<div class="fb-comments" data-href="http://stabmail.com/study-groups-tutoring/#comm-esl" data-width="880" data-num-posts="20"></div>
<div class="fb-comments" data-href="http://stabmail.com/study-groups-tutoring/#psyc" data-width="880" data-num-posts="20"></div>
Perhaps your issue could be solved by simply removing 'index.html', as Facebook would then treat the '#tab' as the page, and not a link to a different part of the page
My solution can be seen working here http://stabmail.com/study-groups-tutoring/
I installed facebook comments on my website. My website is a dynamic website and pages are like this www.example.com/page?id=54, www.example.com/page?id=67.
If I post a comment in this page: www.site.com/page?id=54, it also appears in www.example.com/page?id=67. The comments are not unique for a page, but appear in every page
i saw the question : Facebook comments, for each page.
The answer in this question is that the problem is because of the "?" sign.
It seems that "?" sign in the URL make it broken for the Facebook plugin.
And I need to change form of URl writing.
Because my website is 7 years old have incoming links to it, I don’t want to change the method of the URl writing .
is there another way to fix it?
Firstly, copy comment div and script from Facebook, paste it to your product details page:
<div id="fb-root"></div>
<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=114215202075258";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
and
<div class="fb-comments" data-href="http://example.com" data-width="470" data-num-posts="3"></div>
Finally, simply add this code:
<script>
$(".fb-comments").attr("data-href", window.location.href);
</script>
If you're using PHP this is the code which will request the URL of the current page and then link Facebook comments to it:
<?PHP
$url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
echo "<div class='fb-comments' data-href='$url' data-num-posts='10' data-width='470'></div>";
?>
It works if your dynamic content has only one query string (for example ?product=). If it has more query strings for the same page, for example &sort= for sorting options, then it won't work properly as the Facebook comment which would appear on sorting option ascending wouldn't appear on the sorting option descending, for example.
You can solve this part by assigning a base URL for that product and then showing the FB comments for that URL on all dynamic pages with that product. For example, you're requesting FB comments for the page ?product=13&sort=asc&type=34 even if &sort and &type are different on that page.
When inserting the widget to your page you add something similar to the following code:
<div class="fb-comments" data-href="http://example.com" data-num-posts="2" data-width="470"></div>
You need to replace http://example.com each time for the new page, once with ?id=54 and another time with ?id=67 for each relevant page.
Hmm, I'm confused. You say the site is 7 years old and you cannot change it, but somehow you recently inserted the like plugin into an unchangeable web site. Now you want ways to fix this unchangeable website.
But, if you could change the website, here's what you're going to need to do:
Put in the required og meta tags into the <head> section of each web page as described on the like plugin documentation web site. You can do this programmatically via the query string parameter using your .asp coding skills.
Test/QA the OG meta tags are correctly specified at https://developers.facebook.com/tools/lint
Add the required html code for the plug in and ensure the href correctly and fully identified in the data-href parameter of the like plug
Test/QA the like button by viewing source on the page being sent down.
EDIT
Take a look at what Facebook sees for your url
http://developers.facebook.com/tools/debug/og/echo?q=http%3A%2F%2Fwww.winebar.co.il%2Fproduct.asp%3Fproductid%3D567%26CatCode%3D182
Notice the plugin code
BAD: data-href="http://winebar.co.il/product.asp?productid="
If should look like the URL in the user's browser bar:
GOOD: data-href="http://www.winebar.co.il/product.asp?productid=567&CatCode=182"
I have added Addthis widget to a website. Here is the autogenerated code which I have tweaked little bit:
<script type="text/javascript">
var addthis_config = {
"data_track_clickback": true,
services_compact: 'facebook, twitter,googlebuzz, digg, stumbleupon',
services_expanded: 'facebook, twitter,googlebuzz, digg, stumbleupon',
ui_cobrand: "ABC Company",
ui_header_color: "#ffffff",
ui_header_background: "#000000"
}
</script>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4dde778a54a20e05"></script>
<script type="text/javascript">
var addthis_share = {
templates: { twitter: 'check out {{title}} : {{url}} #ABC' },
url_transforms : { clean: true }
}
</script>
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_compact">
<img alt="Share" src="../images/icons/share.gif" /><img alt="ABC" src="../images/icons/financial_tip.png" />
</a>
</div>
I have added facebook, twitter, google buzz, StumbleUpon and Digg links inside the ADdthis compact and expandable widgets.
When I click the Share link, following window pop ups:
I dont want the Addthis footer to appear in the pop up window. I tried finding the div with jquery doc load and removing it..but it didnt help.
Other thing is when I click FB, it opens my account and the following message is displayed about posting on my wall:
Addthis is appending some garbage at the end of the shared url:
e.g after index.aspx starting from # to ;facebook ..it is appending some data that is irrelevant... how to fix it ..any idea...
If I share it on twitter, the login screen to twitter
I dont want the Addthis message in footer..how to hide/delete it
Similar to FB, when i login to my twitter account, some garbage is added to the end of the shared url:
Moreover, whenever i click any icon inside the compact Addthis list, Fb or twitter, a small window pop ups:
Can anyone help me with these.
THanks.
About twitter issue, you can use somthing like this..
<script type='text/javascript'>
var addthis_share =
{
templates: { twitter: '{{title}}: {{url}}' }
}
</script>
And change
<a class='addthis_button_tweet' tw:via='YOUR-USER-NAME'/>
I never tried other services. But have a look at Addthis API. I think you can find out something.
Malinda's answer is basically correct but doesn't explain what's going on - I think it's important to understand a bit more.
The question says, "Addthis is appending some garbage at the end of the shared url". This isn't garbage. The value after the #hashtag is a semi-random number generated by Addthis that can help you build really useful social media reports that can even show you which of your shares are re-shares - a critical component in modeling viral growth rates (which is what you want from social sharing). You can read more about that here: http://support.addthis.com/customer/portal/articles/381254-address-bar-sharing-analytics.
What Malinda's solution does is override the default Addthis Twitter template to omit this tracking data. That certainly works - you should just realize what you're giving up in terms of tracking your social media campaign.