【发布时间】: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