By jfmoore on
I found this post here:
http://drupal.org/node/553396#comment-2263590
which gave the code below for a block to display nodes by the same author for Drupal 6.
<?php
$nlimit = 15; //max nodes to show, edit this value
$node_type = 'story'; //type of node to display in this block
if (arg(0) == 'node' && is_numeric(arg(1))) {
$output = null;
$nid = arg(1);
$node = node_load(array('nid' => $nid));
$author = $node->uid;
$result = db_query("SELECT n.created, n.title, n.nid, n.status, n.type
FROM node n
WHERE n.uid = $author AND n.status = 1 AND n.type = '$node_type' AND n.nid not in ('$node->nid')
ORDER BY n.created DESC
LIMIT $nlimit");
$output = '<ul id="authored_nodes" class="menu">';
while ($obj = db_fetch_object($result)) {
$output .= '<li class="leaf">';
$output .= l(($obj->title), "node/".$obj->nid);
$output .= '</li>';
}
$output .= '</ul>';
echo $output;
}
?>
Trouble is, it is for only one node type, and that, for me anyway, is not very useful. I don't want to have to have 4 or 5 different blocks for different node types. How would you modify the above code for multiple node types?
Comments
Have you considered just using the views module?
This would be super easy to accomplish with views. You could just pass in the node author as the default argument and display the view on any pages where you wanted to see other nodes with the same author.
I would also recommend views
I would also recommend views but if you want to use the snippet but do not care about node type remove
n.type = '$node_type' AND._
Yep, i usually recommend views for this type of thing but if you really want to code it manually just change the following line:
Thanks, bur I'm not sure what
Thanks, bur I'm not sure what you mean. If you replace this line:
with this one:
...it doesn't work, and if you replace these lines:
with these lines:
...it doesn't work, either. Can you please elaborate?
_
Replace the original statement from the code you posted:
with the snippet I posted:
That works fine. Thanks.
That works fine. Thanks. Turns out, though, that it's too broad in that it includes all node types. What if you wanted to specify just certain node types to be displayed and not others? How would you display, for example, story, page, and blog node types alone (and, of course, any other types one might want to later add?
_
Then add some 'AND n.type =' pieces to the sql.
Like this?: $result =
Like this?:
Is this correct?