【问题标题】:How Do I Create a Blogger Static Page Listing Recent Comments?如何创建列出最近评论的 Blogger 静态页面?
【发布时间】:2016-02-15 06:52:56
【问题描述】:

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

我想为“最近的评论”添加一个标签,因为我认为“评论小部件”被埋在一边,无论如何都没有显示足够的 cmets。我在想,如果我给人们一个列出几十个 cmets 的特定页面,我会得到更多人的回应。

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

但肯定有更好的方法。

【问题讨论】:

    标签: widget comments blogger


    【解决方案1】:

    为 cmets 创建新的静态页面并以“HTML”模式编辑页面。

    然后你可以粘贴这样的脚本来显示最近的 cmets:

    <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 输出和样式,并根据您要显示的内容添加/删除对象。

    【讨论】:

    • 像魅力一样工作!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-21
    • 2014-11-04
    • 2015-04-08
    相关资源
    最近更新 更多