PDA

View Full Version : Blogspot.com: Show per post comments under each article (Javascript & JSON)



mastermindsro
01-11-2008, 01:01 PM
Hello everybody,

I have a blogspot.com blog:

I'm currently struggling to place the recent comments of a specific
article just under it (per post comments).

So here is the code that doesn't work:

---------------------------------------------------
In the blog source:
---------------------------------------------------


<script type='text/javascript'>
post_id_for_comments = '<data:post.id/>';
</script>
<script src='http://www.masterminds.ro/external/politicanoastra/unelte/
ucpa/ucpa.js' type='text/javascript'/>

---------------------------------------------------
In an external javascript (called "ucpa.js"):
---------------------------------------------------


<script style="text/javascript" src="http://www.masterminds.ro/
external/politicanoastra/interfata/jss/ultimele_comentarii.js"></
script>
<script style="text/javascript">var a_rc=25;var m_rc=true;var
n_rc=true;var o_rc=100;></script>
<script type="text/javascript">

<script type="text/javascript">
<!--
document.write('<script src="http://politicanoastra.blogspot.com/
feeds/', post_id_for_comments, '/comments/default?alt=json-in-
script&callback=showrecentcomments" type="text/javascript"><\/
script>');
// -->
</script>

---------------------------------------------------
In an external javascript (called "ultimele_comentarii.js"):
---------------------------------------------------


function showrecentcomments(json){for(var i=0;i<a_rc;i++){var
b_rc=json.feed.entry[i];var
c_rc;if(i==json.feed.entry.length)break;for(var
k=0;k<b_rc.link.length;k++){if(b_rc.link[k].rel=='alternate')
{c_rc=b_rc.link[k].href;break;}}c_rc=c_rc.replace("#","#comment-");var
d_rc=c_rc.split("#");d_rc=d_rc[0];var
e_rc=d_rc.split("/");e_rc=e_rc[5];e_rc=e_rc.split(".html");e_rc=e_rc[0];var
f_rc=e_rc.replace(/-/g," ");f_rc=f_rc.link(d_rc);var
g_rc=b_rc.published.$t;var h_rc=g_rc.substring(0,4);var
i_rc=g_rc.substring(5,7);var j_rc=g_rc.substring(8,10);var k_rc=new
Array();k_rc[1]="Ian";k_rc[2]="Feb";k_rc[3]="Mar";k_rc[4]="Apr";k_rc[5]="Mai";k_rc[6]="Iun";k_rc[7]="Iul";k_rc[8]="Aug";k_rc[9]="Sep";k_rc[10]="Oct";k_rc[11]="Noi";k_rc[12]="Dec";if("content"
in b_rc){var l_rc=b_rc.content.$t;}else if("summary" in b_rc){var
l_rc=b_rc.summary.$t;}else var l_rc="";var re=/<\S[^>]*>/
g;l_rc=l_rc.replace(re,"");
if(m_rc==true)

document.write('<font face="Arial">Pe '+j_rc+' '+k_rc[parseInt(i_rc,
10)]+' ');
document.write('<a href="'+c_rc+'"
target="_parent"><b>'+b_rc.author[0].name.$t+'</a></b> a
spus:');if(n_rc==true)
document.write('<br> ');
if(l_rc.length<o_rc){
document.write('<i>“');
document.write(l_rc);
document.write('”</i><br/>');
document.write('<a href="'+c_rc+'" target="_parent"><b>Acesta este
intreg comentariul</a></b><br><br><hr><br>');
}

else{
document.write('<i>“');
l_rc=l_rc.substring(0,o_rc);
var p_rc=l_rc.lastIndexOf(" ");
l_rc=l_rc.substring(0,p_rc);
document.write(l_rc+'&hellip;”</i>');
document.write('');if(n_rc==true)
document.write('<br><a href="'+c_rc+'" target="_parent"><b>Vezi intreg
comentariul</a></font></b><br><br><hr><br>');}}
document.write('<div style="font-size:70%;text-align:center"></
div>');}

------------------------------------------------------------------------------------------------------------

So why it isn't work? If I replace the "data:post.id" in the external
javascript writing manually he's id like "2618945762366297266"
everything works but the problem is how to include "data:post.id"
dynamic data into the script...

pman
01-12-2008, 01:13 AM
---------------------------------------------------
In an external javascript (called "ucpa.js"):
---------------------------------------------------


<script style="text/javascript" src="http://www.masterminds.ro/
external/politicanoastra/interfata/jss/ultimele_comentarii.js"></
script>
<script style="text/javascript">var a_rc=25;var m_rc=true;var
n_rc=true;var o_rc=100;></script>
<script type="text/javascript">

<script type="text/javascript">
<!--
document.write('<script src="http://politicanoastra.blogspot.com/
feeds/', post_id_for_comments, '/comments/default?alt=json-in-
script&callback=showrecentcomments" type="text/javascript"><\/
script>');
// -->
</script>


Firstly, there's no such attribute for Script tag named Style. It should be "Type"

Secondly and most importantly, you have html code in the javascript file. Don't enter

<script type="text/javascript">....</script>

in your javascript source