2012年9月28日星期五

通过Javascript在Blogger首页显示/隐藏评论


示例如本Blog贴子,点击"评论"选项即可看到

使用前请将全角符号<>更改为半角

1.添加CSS于<style></style>之间

.commenthidden {display:none}

.commentshown {display:inline}


2.在模板的 <head></head> 标记间添加以下Javascript代码:



<script type="text/Javascript">


function togglecomments (postid) {


var whichpost = document.getElementById(postid);


if (whichpost.className==

"commentshown") {

whichpost.className="commenthidden";

}

else {

whichpost.className="commentshown";

}

}

</script>


3.在<Blogger> </Blogger>

之间找到如下类似代码:


<MainOrArchivePage>

<BlogItemCommentsEnabled>

<a href="<$BlogItemPermalinkURL$>#comments">

<$BlogItemCommentCount$> comments</a>

</BlogItemCommentsEnabled>


</MainOrArchivePage>


去掉包围的<MainOrArchivePage></MainOrArchivePage>标记,以让评论在所有页面上显示.

之后,要将代码替换成以下类似形式:


<BlogItemCommentsEnabled>

<a href="javascript:togglecomments('c<$BlogItemNumber$>')">


<$BlogItemCommentCount$> 评论</a>

</BlogItemCommentsEnabled>


4.一般紧跟我们刚找到的代码下有以下类似代码(就是在贴子页中显示评论的那部分代码):

<ItemPage>

<BlogItemCommentsEnabled>

中间省略一部分标记

</BlogItemCommentsEnabled>

</ItemPage>


首先去掉<ItemPage></ItemPage>两个标记,以让评论内容在所有页面上显示.

最好要添加类似代码以显示和隐藏评论:

<span class="commenthidden" id="c<$BlogItemNumber$>">

<BlogItemCommentsEnabled>

中间省略部分标记

</BlogItemCommentsEnabled>

</span>

没有评论:

发表评论