be able to change disqus_identifier on some pages

I’m using the wordpress plugin.

I’ve found the code in the plugin file “comments.php” that defines the identifier for a page:

Read More
var disqus_identifier = '<?php echo dsq_identifier_for_post($post); ?>';

What I’ve come up with so far is to replace it with:

var disqus_identifier = '<?php echo get_post_meta($post->ID, 'dis_ident_field', true); ?>';

This means that it will get it’s disqus_identifier from a custom field from WordPress called dis_ident_field, but I’m worried about this method. For pages where I don’t populate this field, I now have no identifier at all in the javascript in the page source.

Can someone explain why having no id is bad, because the comments still work on all those pages properly, so it’s getting an id from somewhere.

Related posts

Leave a Reply

2 comments

  1. You could use something like this to check if its set before using it or set it to the page id.

    <?php 
    //Attempt to get identifier
    $disqus = get_post_meta($post->ID, 'dis_ident_field', true);
    //if isset & not blank else use $post->ID
    $disqus = (!empty($disqus)) ? $disqus : $post->ID;
    ?>
    
    var disqus_identifier = '<?=$disqus?>';
    
  2. I had to get some band reviews that were already in Disqus from my old site into my new WordPress band site. I only wanted the reviews on our home page so here’s what I did…

    I looked at the code on my old site and grabbed the disqus_identifier value from there.

    I defined and added a custom field named “dsq_identifier” to my custom page template and gave it the disqus_identifier value from my old site.

    I’m new to WordPress and PHP and I’m sure this is a bad idea, but I needed to get this done, so…

    I edited the Disqus plugin’s comment.php by adding this code after all the var initialization:

    <?php if ( get_post_meta($post->ID, 'dsq_thread_id', true) ) : ?>
      disqus_identifier = '<?php echo get_post_meta($post->ID, 'dsq_identifier', true); ?>';
    <?php endif; ?>
    

    Since I only want to display the review comments on our home page which has the custom field named “dsq_identifier,” I modified my custom template (which used by several pages). Here’s that code:

    <?php if ( get_post_meta($post->ID, 'dsq_identifier', true) ) : ?>
      <?php comments_template(); ?> 
    <?php endif; ?>
    

    BAAAMMM! Worked the first time.

    If you have any ideas about how to get this to work without changing the Disqus plugin code base, that would rock. I need to take a step back and really think this over after the new site is released in a couple of days.