Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
and node_load() returns an object for a single node/nid. So if you only have one node/nid you can do
$set = array();
$set[] = node_load($nid);
and that would give you an array with one element which is a node object. If you have more than one nid, you could loop through the set of nid's doing a node_load() for each need, adding the return to an array (like the example above).
But in the truth i dont want this .. what i want is get node information like forum_get_topics() (form.module) make.
if it was possible to pass as parameter from forum_get_topics() a nid array it would be more easily.
what I want I am accurately one equal Array to the returned one for forum_get_topics (), I am making a custom search in the forum, and in this search i have the results in array of nid and i need display this result in a page of my forum. You understand?
One thing that is confusing is the forum_get_topics does not simply return an array of nodes, it returns information about forum topics.
The following function is based on forum_get_topics but takes an array of nids instead of a tid (note this is untested)
function your_forum_get_topics($nids, $sortby, $forum_per_page) {
global $user, $forum_topic_list_header;
$forum_topic_list_header = array(
array('data' => ' ', 'field' => NULL),
array('data' => t('Topic'), 'field' => 'n.title'),
array('data' => t('Replies'), 'field' => 'l.comment_count'),
array('data' => t('Created'), 'field' => 'n.created'),
array('data' => t('Last reply'), 'field' => 'l.last_comment_timestamp'),
);
$order = _forum_get_topic_order($sortby);
for ($i = 0; $i < count($forum_topic_list_header); $i++) {
if ($forum_topic_list_header[$i]['field'] == $order['field']) {
$forum_topic_list_header[$i]['sort'] = $order['sort'];
}
}
if ( is_array($nids) ) {
$nid_str = implode(',', $nids);
}
else if ( empty($nids) ) {
return array();
}
else {
$nid_str = $nids;
}
$term = taxonomy_get_term($tid);
$sql = db_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid != 0, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node_comment_statistics} l, {users} cu, {users} u, {forum} f, {node} n WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid IN (%s) AND n.uid = u.uid AND n.vid = f.vid");
$sql .= tablesort_sql($forum_topic_list_header, 'n.sticky DESC,');
$sql .= ', n.created DESC'; // Always add a secondary sort order so that the news forum topics are on top.
$sql_count = db_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1 AND n.type = 'forum' AND n.nid IN (%s)");
$result = pager_query($sql, $forum_per_page, 0, $sql_count, $nid_str);
while ($topic = db_fetch_object($result)) {
if ($user->uid) {
$history = _forum_user_last_visit($topic->nid);
$topic->new_replies = comment_num_new($topic->nid, $history);
$topic->new = $topic->new_replies || ($topic->timestamp > $history);
}
else {
// Do not track "new replies" status for topics if the user is anonymous.
$topic->new_replies = 0;
$topic->new = 0;
}
if ($topic->num_comments > 0) {
$last_reply = new stdClass();
$last_reply->timestamp = $topic->last_comment_timestamp;
$last_reply->name = $topic->last_comment_name;
$last_reply->uid = $topic->last_comment_uid;
$topic->last_reply = $last_reply;
}
$topics[] = $topic;
}
return $topics;
}
Comments
example...
A function like (this function not exists, its an assumption)
node_get_info($nid);and this function returns:
Like a forum_get_topics() make in $topics array.
$node =
$node = node_load(array('nid' => $nid));
http://api.drupal.org/api/5/function/node_load
That what you are after?
Minor note
If you have a nid it is better to call the function like this
which if the node has already been loaded will use a cached copy.
Ok .. its works!
Ok, its works .. but i need an array like array returned by forum_get_topics() in var $topics.
One array like example below:
Exists function to make this?
What you have is an array of objects
and node_load() returns an object for a single node/nid. So if you only have one node/nid you can do
and that would give you an array with one element which is a node object. If you have more than one nid, you could loop through the set of nid's doing a node_load() for each need, adding the return to an array (like the example above).
Hi nevets, thanks for your
Hi nevets, thanks for your answer.
But in the truth i dont want this .. what i want is get node information like forum_get_topics() (form.module) make.
if it was possible to pass as parameter from forum_get_topics() a nid array it would be more easily.
what I want I am accurately one equal Array to the returned one for forum_get_topics (), I am making a custom search in the forum, and in this search i have the results in array of nid and i need display this result in a page of my forum. You understand?
Given you have an array of nids this might help
One thing that is confusing is the forum_get_topics does not simply return an array of nodes, it returns information about forum topics.
The following function is based on forum_get_topics but takes an array of nids instead of a tid (note this is untested)