【问题标题】:Disqus Loading the same comments for dynamic pagesDisqus 为动态页面加载相同的评论
【发布时间】:2012-02-15 04:31:12
【问题描述】:

我有一个加载不同想法的动态页面。我正在为 cmets 使用 disqus,但 disqus 不断为每个想法加载相同的 cmets。

这里是网站。 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>

请帮助解决导致错误的原因以及我可以做些什么来解决它

【问题讨论】:

    标签: javascript disqus


    【解决方案1】:

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

    【讨论】:

    • 你好 Cheeken,$title 是每个想法的标题。当您查看每个idea页面的来源时,您会看到disqus_identifier是不同的。这意味着标题正确呈现。
    • 感谢 Madmartigan,将 disqus_url 设置为与 disqus_identifier 相同已解决问题。
    【解决方案2】:

    您的标识符似乎不够唯一,请参阅此处的参考文档:http://docs.disqus.com/help/14/

    它说:

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

    【讨论】:

    • 感谢 Jakub,我通过使用 URL 作为标识符解决了这个问题。但我怀疑每个想法都有自己的标题。这还不足以让 Disqus 使用吗?
    • @Stanley,看起来它不够独特,有时越独特越好,除了谁在乎它是唯一标识符之外,您可以对其进行哈希处理,它仍然可以工作。
    【解决方案3】:

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

    DISQUS.reset({ 
        reload: true, 
         config: function () { 
           this.page.identifier = 'http://example.com/#!' + myPageID;
           this.page.url = 'http://example.com/#!' + myPageID;
         }}); 
    

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

    【讨论】:

    • 我找到的所有解决方案都不起作用,但你的解决方案都不起作用,这不是很奇怪,这绝对是一个 Disqus 问题,但你的评论救了我,谢谢。
    【解决方案4】:

    我终于得到了这个工作如下。

    Ajax 站点的 Disqus 文档 [1] 指出 requirements 将使用 full hashbang #! 设置变量 this.page.identifierthis.page.URL

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

    令人困惑的是,上述文档中链接的示例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

    【讨论】:

    • 这导致谷歌在我的网站上抓取数百个重复页面,使用 hashbang 是个坏主意。
    • @idan-shechter 我同意...由于许多其他原因,我已经停止使用它。请注意,Disqus 似乎对非基于服务器的安装没有任何真正的支持。许多人对他们的奉献不满意。例如。 randocity.com/2017/10/26/…
    猜你喜欢
    • 1970-01-01
    • 2013-07-17
    • 2013-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多