Display comments of a node on another page
Note from the moderator: Thank you for sharing the snippet with the Drupal community. In its current state the snippet might present security risks. See Writing secure code for a background on the most common problems.
Specifically, the snippet
- bypasses node access restrictions; you should usually pass queries through db_rewrite_sql.
This is maybe not a scipt for beginners. This is a useful script when you want to show news or information on a page and want to use an easy interface for your moderators. Example: Create a new node (for example in a organic group where only your moderators can access this node and add comments to it). Then add some comments to this node (which will be shown as news later). Paste this script on a page and change the node_id value (where the number is 638) to the node you created. Now your moderators can change news on the page by simply adding comments on the created node.
<?php
//node comments show -----------------------------------------
//shows comments from a specific4.6 section node
//edit these values
$show = 2;//show for: 0 = None (off) 1 = guests 2 = all 3 = logged in:
$node_id = 638; //node id number, change this
//start --------------------------------------------------
unset($output);
global $user;
if (($user->uid >= $show-2 AND $show >= 2)
OR ($user->uid == 0 AND $show == 1)) {
//comments start --------------------------------------------
print '<TABLE BORDER="1" CELLPADDING="1" CELLSPACING="3" WIDTH="100%"><TR><TD>';
print '<IMG SRC="pic/sq2.jpg" ALT="Starflower" Align="right">';
$se="
SELECT *
FROM comments
WHERE nid = $node_id AND status = 0
ORDER BY timestamp
DESC ";
$result = db_query_range($se, 0, 10);
while ($obj = db_fetch_object($result)) {
print '<h3>';
print $obj->subject;
print '</h3>';
print $obj->comment;
print '<BR>';
}
print '</TD></TR></TABLE><BR>';
//comments end --------------------------------------------------------
}
?>