【问题标题】:Disqus comment count not workingDisqus评论计数不起作用
【发布时间】:2014-02-13 15:15:31
【问题描述】:

我在 WordPress 主题中手动安装了 Disqus(通过插件根本无法使用)。它工作正常,但我无法显示评论数。

我认为我在做很多事情都很艰难:

/blog/页面上的链接如下:

<a href="/the-post-title/#disqus_thread" data-disqus-identifier="dq-332" title="The Post Title"><i class="fa fa-comment"></i> 0</a>

cmets.php:

<?php if (comments_open()) : ?>
<div id="disqus_thread"></div>
<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'myshortname'; // Required - Replace example with your forum shortname
    var disqus_identifier = 'dq-<?php echo get_the_ID(); ?> ';

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();

    alert(disqus_identifier);

</script>
<noscript>Please enable JavaScript to view the comments.</noscript>

如您所见,我正在提醒 disqus_identifier,因此可以验证它的设置是否正确(在这种情况下 dq-332 如上所述)

我正在全局加载 count.js

<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'myshortname'; // required: replace example with your forum shortname

/* * * DON'T EDIT BELOW THIS LINE * * */
(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>

我只让它在一种(错误的)情况下工作:

在我尝试使用data-disqus-identifier 之前,它通过将#disqus_thread 附加到永久链接而不使用尾部斜杠来工作,例如http://mydomain.com/the-post-title#disqus_thread

问题在于那里的 cmets 不会出现在 http://mydomain.com/the-post-title/http://mydomain.com/the-post-title/#disqus_thread 中(与随处可见的 WordPress 生成的尾部斜杠相同)。

这就是我最终采用标识符方法的原因。到目前为止没有任何影响。对任何类型的提示都会很高兴。干杯!

【问题讨论】:

    标签: javascript wordpress disqus


    【解决方案1】:

    无法通过这种方式解决。花了更多时间调查为什么 WordPress 插件不起作用。最终解决了。

    注意:您不应该使用 disqus 激活任何相对 URL 插件。

    【讨论】:

    • 那么你能告诉我问题出在哪里吗?我有同样的问题。
    • 好的,我发现它在本地不工作,但在我们的服务器上工作。 JavaScript 只是将 cmets 的数量加上一个空格添加到锚标记的 InnerHtml。
    • 在我的情况下,这是一个与某些相对 URL 插件不兼容的插件
    猜你喜欢
    • 1970-01-01
    • 2013-08-07
    • 2018-03-20
    • 2015-10-11
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 2013-12-12
    相关资源
    最近更新 更多