0

Now, I am having comments section like this in node view page.

 Comment 1 comment 11 comment 12 Comment 2 Comment 3 comment 31 comment 32 comment 33 

But, I would to show this with show/hide option for replied comments with replies count. like below

 Comment 1 show/hide 2 replies ------------------ | comment 11 | | comment 12 | ------------------ Comment 2 Comment 3 show/hide 3 replies --------------- | comment 31 | | comment 32 | | comment 33 | --------------- 

1 Answer 1

6

I tried to solve your problem . The best way to solve this is to create a new CUSTOM MODULE. - Create a new folder in Your sites/all/modules folder custom_module name could be anything.

  • In folder create two files custom_module.info and custom_module.module and a folder js . In that folder create a .js file custom_module.js .
  • So now you .js file will be located at sites/all/modules/custom/js/custom_module.js . Now Go to custom_module folder and in custom_module.info file add the lines of code..

    name = Custom_module description = Displays total count of replies to a comment and add display toggler to the replies of the comment. core = '7.x' version = '7.x-1.x' dependencies[] = comment 
  • Now in your custom_module.module file

    <?php drupal_add_js(drupal_get_path('module','custom_module') '/js/custom.js'); function custom_module_preprocess_comment(&$variables) { $query = db_query('SELECT COUNT(*) FROM comment WHERE pid = :cid', array(':cid' => $variables['id'])) ; $result = $query->fetchField(); $variables['content']['links']['comment']['#links']['comment-reply']['title'] = 'reply </a> <span>('.$result.')</span> <span id="show-hide">Show</span>'; } 
  • So what the module did is fetched the total no of replies of a comment from the database and appended them to reply link.

  • A Simple jQuery file will get you what you wanted. Edit your js/custom_module.js file custom_module.js file

    (jQuery)(document).ready( function() { jQuery('div.indented').css('display', 'none'); (jQuery)('div.comment .comment-text ul li.comment-reply span').click( function() { if(jQuery('show-hide').html()=='Show') { jQuery('show-hide').html()='Hide'; (jQuery)(this).parents("div.comment").next().slideToggle(); } else { jQuery('show-hide').html()='Show'; (jQuery)(this).parents("div.comment").next().slideToggle(); } }); })(jQuery); 
  • Click On Show in Comments and it will toggle . I have also added a screenshot..

SHOW Show.

HIDE Hide

2
  • Could you elaborate how should he do it and what he's supposed to put inside that function? Commented Jun 13, 2013 at 8:53
  • 1
    Thanks Swastik Pareek. I am the beginner to drupal module. So, I did everything jquery. Commented Jun 18, 2013 at 10:31

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.