runeveryday
runeveryday

Reputation: 2799

modify the comment reply link

now, i want to modify the comment reply link,the effect which i love is like the wordpress's. when i click the "reply" link. it takes me to the comment box which at the bottom of the page.just like the name anchor. not taking me to a new page, any tips would be appreciated.

Upvotes: 2

Views: 2119

Answers (3)

Vodde
Vodde

Reputation: 375

First, go to the Edit page of your Content Type. Then, find the "Comment Settings", and put the option "Location of comment submission form" on "Display below post or comments"

Edit your suiting node template file, and print a reply link, like for example :

<a href="#addComment"><?php print t('Add Comment'); ?></a>

Add some funky jQuery to the link, to scroll to the Form for example, and you're off. For example :

Drupal.behaviors.initCommentLink = function(context) {
  // Hide the comment form
  $('#comment-form').hide(); 

  // Add click handler to our custom relpy link
  $('a[href=#addComment]').click(function(){
    $('#comment-form').fadeIn('slow');
    var targetOffset = $('#comment-form').offset().top;
    $('html,body').animate({
      scrollTop : targetOffset
    },'slow');
    $(this).fadeOut('fast');
  }); 
}

If all goes well, you should now see a Reply link, but no Comment Form. Clicking on the Reply link should make the Comment form appear, and make the Page scroll to the Form. In addition, the Reply link should be hidden after clicking it.

If you don't know jQuery, no worries, the code should work if you put it in a regular JS file, just make sure that it is included. To make sure of that, put it in the JS file that you have in your theme.

Upvotes: 0

Nikit
Nikit

Reputation: 5128

use ajax_comments

Upvotes: 2

Collin White
Collin White

Reputation: 680

You can setup that file like so

$nid = arg(1);
$node = node_load($nid);
$node->comment = COMMENT_NODE_READ_WRITE;
$commentLink = comment_link('node',$node);

You can test for login status etc here too and place it in your view.

Upvotes: 0

Related Questions