Disqus为动态页面加载相同的注释

时间:2012-01-20 16:05:15

标签: javascript disqus

我有一个动态页面,可以加载不同的想法。我正在使用disqus作为评论,但是disqus继续为每个想法加载相同的评论。

这是网站。 http://tech-in.org/submitted_ideas/index.php

这是我的代码

<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
     if( typeof DISQUS != 'undefined' ) { 
      DISQUS.reset({ 
        reload: true, 
         config: function () { 
           this.page.identifier = '<?php echo $title; ?>'; 
           this.page.url = 'http://tech-in.org/submitted_ideas/idea.php?id=<?php echo $idea_id; ?>'; 
         } 
       }); 
    } 
    var disqus_shortname = 'techinorg'; // required: replace example with your forum shortname
    var disqus_identifier = '<?php echo $title; ?>';
    var disqus_url = 'http://tech-in.org/submitted_ideas/idea.php?id=<?php echo $idea_id; ?>';
    var disqus_title = document.getElementById('disqus_post_title').innerHTML;
    var disqus_message = document.getElementById('disqus_post_message').innerHTML;


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

请帮助解决导致错误的原因以及如何解决此问题

4 个答案:

答案 0 :(得分:5)

Disqus根据您指定的disqus_identifier决定加载哪些评论。加载不同的“想法”时,请确保提供与该想法相对应的唯一disqus_identifier。 (目前尚不清楚PHP脚本中$title代表什么,这是当前分配给disqus_identifier的内容。)

答案 1 :(得分:5)

您的标识符看起来不够独特,请参阅此处的参考文档:http://docs.disqus.com/help/14/

它声明:

  

当访问Disqus启用Disqus页面时,Disqus使用此标识符   确定要加载的相应注释线程。如果合适的话   找不到线程,创建一个新线程。 Disqus标识符   保持线程和页面的关联。

答案 2 :(得分:1)

我在使用AJAX使用新的disqus线程加载新内容的页面上遇到了同样的问题。我的解决方案是将标识符和URL设置为相同的东西。

CompositionTarget.rendering

其中myPageID是我使用AJAX动态更新的整数

答案 3 :(得分:0)

我终于得到了如下工作。

针对Ajax网站的Disqus doco [1],指出requirements是使用this.page.identifier设置变量this.page.URLfull hashbang #!

var disqus_config = function () {
    this.page.identifier = window.location.origin + '/#!' + identifier 
    this.page.url = window.location.origin + '/#!' + identifier
}

令人困惑的是,在上面提到的doco中链接的示例recipe [2]并没有这样做。

参考文献:

[1] https://help.disqus.com/customer/portal/articles/472107-using-disqus-on-ajax-sites

[2] https://github.com/disqus/DISQUS-API-Recipes/blob/master/snippets/js/disqus-reset/disqus_reset.html

相关问题