Singpolyma

Technical Blog

Commentosphere Blogger Integration

Posted on

I have finalised the first version of a template hack for Blogger that inlines Commentosphere data for comments on your blog. This allows you to make better use of the semi-threading features of Commentosphere. Insert only the code snippets for the data you want (the first two are invisible and mandatory).

  1. Insert this code somewhere in the post section of your template (it is invisible, so it doesn’t matter where):
    <script type=”text/javascript”>
    //<![CDATA[
    posturl = ‘<$BlogItemPermalinkUrl$>’;
    //]]>
    </script>
  2. Insert this code right after your <BlogItemComments> tag:
    <script type=”text/javascript”>
    //<![CDATA[
    csdata = {};
    for(var i=0; i<Commentosphere.posts.length; i++) {
    if(Commentosphere.posts[i].url == posturl+’#c<$BlogCommentNumber$>’ || Commentosphere.posts[i].url == posturl+’#<$BlogCommentNumber$>’) {
    csdata = Commentosphere.posts[i];
    break;
    }//end if url == this
    }//end for
    //]]>
    </script>
  3. Insert this code where you want the links to parents of the comment (if there are any) to show up:
    <script type=”text/javascript”>
    //<![CDATA[
    if(csdata.parents && csdata.parents[0] != ”) {
    document.write(‘(‘);
    for(var i=0; i<csdata.parents.length; i++) {
    if(i > 0)
    document.write(‘ | ‘);
    parenturl = ‘#’+csdata.parents[i].split(‘#’)[1];
    document.write(‘<a href=”‘+parenturl+'”>parent #’+(i+1)+'<\/a>’);
    }//end for
    document.write(‘)’);
    }//end if
    //]]>
    </script>
  4. Insert this code where you want the links to replies to the comment (if there are any) to show up:
    <script type=”text/javascript”>
    //<![CDATA[
    if(csdata.children && csdata.children[0] != ”) {
    for(var i=0; i<csdata.children.length; i++) {
    if(i > 0)
    document.write(‘ | ‘);
    childurl = ‘#’+csdata.children[i].split(‘#’)[1];
    document.write(‘<a href=”‘+csdata.children[i]+'”>reply #’+(i+1)+'<\/a>’);
    }//end for
    }//end if
    //]]>
    </script>
  5. Insert this code where you want the link to the comment on Commentosphere and tags to show up:
    <script type=”text/javascript”>
    //<![CDATA[
    if(csdata.id) {
    document.write(‘ <a href=”http://comment.ning.com/index.php?id Commentosphere</a> ‘);
    }//end if
    if(csdata.tags && csdata.tags[0] != ”) {
    document.write(‘ – Tags: ‘);
    for(var i=0; i<csdata.tags.length; i++) {
    document.write(‘ <a href=”csdata.id[i]+'”>’+csdata.tags[i]+'<\/a> ‘);
    }//end for
    }//end if
    //]]>
    </script>
  6. Save your template and republish your blog
http://del.icio.us/singpolyma.techblog/blogger

Leave a Response