I would like to have a facebook-like dynamic latest nodes loader in Drupal sidebar working in JQuery. Each time new node is created, the users would be able to see it in a list (similar to facebook) without refreshing the page. Any advice, tutorial links, etc. will be appreciated.
+1
A:
How familiar are you with module development? I will suggest the easier, less instant way. If you really wanted it to be updated only when a new node was added, it would take much more work. If someone wants to describe that, they are more than welcome to.
Really all you need to write is a block (hook_block) which inputs some javascript which:
- Sends an AJAX query to a page your module defines (say /nodes/new)
- Displays the data in the block (via the ajax callback).
- Uses set_timeout javascript call to make the call again every so often.
The page will be defined in a hook_menu call with 'type' => MENU_CALLBACK and calling a custom function (my_module_nodes_new).
function my_module_nodes_new() {
$output = '';
$result = db_query("SELECT nid FROM {node} WHERE status = 1 LIMIT 5 ORDER BY `created` DESC");
while($nid = db_fetch_object($result) {
$node = node_load($nid->nid);
// Theme the information here and add it to $output
}
print $output; //IMPORTANT - do not "return" $output or it will be inside your theme
}
Hope that helps!
Chris Ridenour
2010-08-06 15:05:04