Several disqus-threads on one page

前端 未结 8 1054
星月不相逢
星月不相逢 2020-12-08 04:51

we have a website where we have list a lot of events, and would like to add discussions to each of the events.

So we wanted to use disqus, and checked it out. Turns

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 05:09

    I wrote an article about this, find it here. http://mystrd.at/articles/multiple-disqus-threads-on-one-page/

    In essence, if you're fine with displaying a single module at a time and using some sort of a "show comments" control, you could do it the following way (using Wordpress and jQuery as an example, but you can adjust the content identifiers based on your needs). In a post loop, insert an extra control for each:

    
       Show comments
    
    

    Afterwards you need a generic function that will use those post parameters and reload Disqus on demand. Mind that the 2012 version of Disqus doesn't have the reset() method yet and therefore this will not work with it.

    // global vars used by disqus
    var disqus_shortname = 'yoursiteshortnameindisqus';
    var disqus_identifier; // made of post id   guid
    var disqus_url; // post permalink
    
    function loadDisqus(source, identifier, url) {
        if (window.DISQUS) {
            jQuery('#disqus_thread').appendTo(source.parent()); // append the HTML to the control parent
    
            // if Disqus exists, call it's reset method with new parameters
            DISQUS.reset({
                reload: true,
                config: function() {
                    this.page.identifier = identifier;
                    this.page.url = url;
                }
            });
        } else {
            //insert a wrapper in HTML after the relevant "show comments" link
            jQuery('
    ').insertAfter(source); disqus_identifier = identifier; // set the identifier argument disqus_url = url; // set the permalink argument // append the Disqus embed script to HTML var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; jQuery('head').appendChild(dsq); } };

    Other than this, I believe you would have to resort to using iframes. Such a solution with Ruby as an example is outlined here - http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/

提交回复
热议问题