In node.tpl.php, I have done some changes, like creating an array of paragraphs:

    $paragraphs = explode("<p>",render($content));

So, I have a for loop for showing the paragraphs, like:

$number = count($paragraphs);

 print render($paragraphs[0]);
  for ($i=1;$i<$number;$i++)
         print render($paragraphs[$i]);

      <a href="#commenting">Put comment for Paragraph <?php echo $i?><br></a>
<?php  } ?>

   <a id="commenting"><?php print render($content['comments']); ?></a> <?php }?>

As you can see I want to create a hyperlink under each paragraph, so when user click on it, they can put comment on the paragraph, But right now, when they click on the hyperlink, it will jump to the end of the page, which has the comment form. If you check the CommentPress website, in the right column, you can see for example, it is said: 5 Comment on Paragraph 1, and when you click on it, it will show the comments and the comment form under that link, I want to have the same thing, I mean, when users click on the link under each paragraph, the comment form displays under that link instead of jumping to the end of the page.

1 Answer 1


I think you will need to do a couple of things. First is to create a comment form under each paragraph:

Drupal 7:

$comment = new stdClass;
$comment->nid = $nid;
$form = drupal_get_form('comment_form', $comment);

print render($form);

Then I would suggest using some jQuery to hide the forms, showing it only when the user clicks on the link. You can assign a unique class to the $form (see form API reference for more info) so that only the comment form for the specific paragraph shows, instead of all of them when any given link is clicked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.