drupal implements methods for adding content under comments on node nodes

Release time: 2014-11-04 10:30:37 Author: Anonymous I want to comment
This article mainly introduces the drupal implementation in the node node comments below the method of adding content, involving the modification of related functions and the use of hook functions, has a certain reference value, need friends can refer to

This article illustrates an example of how drupal implements adding content under comments on node nodes. Share with you for your reference. The specific implementation method is as follows:

The comment node display for Node in drupal is controlled by the following function. This function is in node.module and looks like this:

Copy code
The code is as follows:
function node_show($node, $cid) {
$output = node_view($node, FALSE, TRUE);
if (function_exists('comment_render') && $node->comment) {
$output .= comment_render($node, $cid);
}
// Update the history table, stating that this user viewed this node.
node_tag_new($node->nid);
return $output;
}

Here's an example of how to add something to a comment on a node node.
First, use the hook_nodeapi hook to write the content to be loaded into the node object. This function is in popularterms.module, and it looks like this:

Copy code
The code is as follows:
function popularterms_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'load':

if($node->type == 'story'){
$node->popularterms_html_content = popularterms_html_content1();
}
break;
}

}

Then write the above addition below the node display of the node_show function.
As follows:

Copy code
The code is as follows:
function node_show($node, $cid) {
$output = node_view($node, FALSE, TRUE);
if (function_exists('comment_render') && $node->comment) {
$output .= comment_render($node, $cid);
}
// Update the history table, stating that this user viewed this node.
node_tag_new($node->nid);
// Comment on "Recent Popular content" added below -jason20080923
$output .= $node->popularterms_html_content;
return $output;
}

The content that needs to be added is displayed under the comments of the node node.

I hope this article will help you with your drupal secondary development.

  • Tag: Drupal

Related article

Latest comments