如何创建列出最近评论的博客静态页面



我有一个由Blogger托管的博客。 http://www.rocketstackrank.com

我想为"最近的评论"添加一个选项卡,因为我认为"评论小部件"被埋在侧面,无论如何都没有显示足够的评论。我在想,如果我给人们一个列出数十条评论的特定页面,我会让更多的人回复他们。

理想情况下,我会以某种方式重新利用现有的最近评论小部件来做到这一点。我对HTML,CSS,JQuery等感到满意,否则,我计划编写一个C#应用程序来使用Blogger API提取注释,然后动态创建页面。(并且每天左右手动运行该程序一次。

但肯定有更好的方法。

为注释创建新的静态页面,并在"HTML"模式下编辑页面。

然后,您可以粘贴如下脚本以显示最近的评论:

<script>
//<![CDATA[
function showrecentcomments(json) {
    for (var i = 0; i < numcomments; i++) {
        var entry = json.feed.entry[i];
        var alturl;
        if (i == json.feed.entry.length) {
            break;
        }
        for (var k = 0; k < entry.link.length; k++) {
            if (entry.link[k].rel == 'alternate') {
                alturl = entry.link[k].href;
                flagAnon = !1;
                break;
            } else {
                // anonymous commenter
                alturl = "http://www.rocketstackrank.com/?showComment=#";
                flagAnon = !0;
            }
        }
        var postlink = alturl.split("?showComment=");
        postlink = postlink[0];
        if ("content" in entry) {
            var comment = entry.content.$t;
        } else
        if ("summary" in entry) {
            var comment = entry.summary.$t;
        } else var comment = "";
        var re = /<S[^>]*>/g;
        comment = comment.replace(re, "");
        if (!standardstyling) document.write('<div class="bbrecpost">');
        if (standardstyling) document.write('<br/>');
        if (flagAnon = !1) {
            document.write('<a href="' + alturl + '" style="text-decoration:none">' + entry.author[0].name.$t + ':' + '</a>   ');
        } else {
            document.write('<a href="' + alturl + '" style="text-decoration:none">' + entry.author[0].name.$t + ':' + '</a>   ');
        }
        if (showposttitle == true) document.write(' in ' + posttitle);
        if (!standardstyling) document.write('</div><div class="bbrecpostsum">');
        if (standardstyling) document.write('<div class="txtmsg"><br/></div>');
        if (comment.length < numchars) {
            if (standardstyling) document.write('<span style="word-break: break-word;">');
            document.write(comment);
            if (standardstyling) document.write('</span>');
        } else {
            if (standardstyling) document.write('<span style="word-break: break-word;">');
            comment = comment.substring(0, numchars);
            var quoteEnd = comment.lastIndexOf(" ");
            comment = comment.substring(0, quoteEnd);
            document.write(comment + '...<a href="' + alturl + '">(Read more)</a>');
            if (standardstyling) document.write('</span>');
        }
        if (!standardstyling) document.write('</div>');
        if (standardstyling) document.write('<br/>');
    }
    if (!standardstyling) document.write('<div class="bbwidgetfooter">');
    if (standardstyling) document.write('<div style="height:6px;width:100%;"></div>');
    if (!standardstyling) document.write('</div>');
}
// Params
var numcomments = 5;
var showposttitle = false;
var numchars = 70;
var standardstyling = true;
//]]>
</script>
<script src='//www.rocketstackrank.com/feeds/comments/summary?max-results=5&alt=json-in-script&callback=showrecentcomments'></script>

确保参数numcomments = INTEGER(在脚本中)等于回调脚本中的max-results=INTEGER

使用参数numchars = INTEGER您可以设置注释预览的长度。

发布您的页面,使 Blogger 编辑器处于 HTML 模式。

作为最后的建议,根据需要检查 HTML 输出和样式,并根据要显示的内容添加/删除对象。

最新更新