Facebook comments box pe pagini dinamice
Salut,
Aici va arat care sunt pasii pentru a adauga plugin-ul de comentarii pe un site cu pagini dinamice cum ar fi:
index.php?site=seopedia&id=23 sau rescrise in .htaccess /seopedia-23(.html)
Sa incepem:
I
https://developers.facebook.com/docs...gins/comments/ creati plugin-ul si il implementati exact cum scrie la punctele 1 si 2
II
Acum intervine javascript care face ca(,) comentariile sa fie postate pe adresa dinamica, nu pe index.php si sa apara pe toate paginile dinamice aceleasi comentarii.
Pentru HTML5
Cod:
<script language="javascript" type="text/javascript">
var uri=document.location.href; //get uri
var isFbPrm=uri.indexOf('fb_comment');
if (isFbPrm!=-1) { // fb comment url
try {
var prm=uri.split("?"); //get paramaters
var url=prm[0]; //url
var prmItm=prm[1].split("&"); //parameter items
var newPrmlst='';
var newUrl='';
for(var j = 0; j < prmItm.length; j++) //read all param to get rid of fb param
{
var prmId=prmItm[j].split("="); //get param id
if (prmId[0]!='fb_comment_id'&&prmId[0]!='ref'&&prmId[0]!='notif_t') { //if parameters are not in the list
newPrmlst +=prmId[0]+'='+prmId[1]+'&';
}
}
uri = url+'?'+newPrmlst;
}
catch (err) {
//Handle errors here
}
}
document.write("<div class='fb-comments' data-href='"+ uri +"' data-width='470' data-num-posts='10'></div>");
</script>
Pentru XFBLM
Cod:
<script language="javascript" type="text/javascript">
var uri=document.location.href; //get uri
var isFbPrm=uri.indexOf('fb_comment');
if (isFbPrm!=-1) { // fb comment url
try {
var prm=uri.split("?"); //get paramaters
var url=prm[0]; //url
var prmItm=prm[1].split("&"); //parameter items
var newPrmlst='';
var newUrl='';
for(var j = 0; j < prmItm.length; j++) //read all param to get rid of fb param
{
var prmId=prmItm[j].split("="); //get param id
if (prmId[0]!='fb_comment_id'&&prmId[0]!='ref'&&prmId[0]!='notif_t') { //if parameters are not in the list
newPrmlst +=prmId[0]+'='+prmId[1]+'&';
}
}
uri = url+'?'+newPrmlst;
}
catch (err) {
//Handle errors here
}
}
document.write("<fb:comments href='"+ uri +"' width='470' num_posts='10'></fb:comments>");
</script>
Acest cod este testat.
Sper sa va fie de ajutor acest topic!