【发布时间】:2017-08-17 16:30:52
【问题描述】:
我有一个使用 Disqus cmets 的 Wordpress 页面。在页面底部我有这个:
<!-- DISQUS COMMENTs -->
<div id="comments">
<div id="disqus_thread"></div>
<script>
/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
var disqus_config = function () {
this.page.url = '<?php the_permalink(); ?>'; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = '<?php the_ID(); ?>'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://example.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
<!-- /#comments -->
在我的页面中,我会显示在当前帖子中创建了多少 cmets,如下所示:
<a href="<?php the_permalink(); ?>#disqus_thread">0 Comments</a>
问题是,它不起作用。即使页面上有 cmets,cmets 也始终显示为零。而且我想我知道为什么会发生这种情况,但我不确定如何解决它。
所以:
我的“cmets”锚呈现如下:
<a href="https://www.example.com/blog/my-post-name#disqus_thread">0 Comments</a>
在底部的 JavaScript 代码中,页面 URL 设置正确,如下所示:
this.page.url = 'https://www.example.com/blog/my-post-name'
但是,如果我发表评论并登录我的 Disqus 控制面板并将鼠标悬停在帖子 URL 上,则 URL 格式如下:
https://www.example.com/blog/?p=232
所以看起来 Disqus JavaScript 在 URL 被重写之前正在读取页面的 URL!这有意义吗?
解决它的一种潜在方法是让我的 cmets 锚呈现如下:
<a href="https://www.example.com/blog/?p=232#disqus_thread">0 Comments</a>
但这感觉有点老套。有什么想法吗?
谢谢!
更新
我可以确认像这样渲染我的 cmets 锚会起作用:
<a href="<?php echo home_url(); ?>/?p=<?php echo get_the_ID(); ?>#disqus_thread">0 Comments</a>
不过,这更像是一种解决方法。如何让 Disqus 存储我重写(看起来更干净)的 URL,而不是 Wordpress 的“普通”(和丑陋的)URL?
【问题讨论】: