hook_nodecarousel?

eelke - April 16, 2009 - 14:08
Project:Nodecarousel
Version:6.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi there,

I was wondering if someone could offer me an example of some hook_nodecarousel code. I have no experience with hook functions. Where to put the function (in the theme template?) and what does it need to return? Can I use a view to return the relevant nodes?
I have read the documentation, but I need some code snippet to get started...

Any help would be appreciated,

Thanks in advance!

#1

jcfiala - April 16, 2009 - 14:28

Right, so, the hook_nodecarousel is invoked when you want to return your nodes as you've picked them.

The basic idea is that you put hook_nodecarousel in a module that you're writing, not the theme.

Let's say that you've created the module misc_module, which includes a misc_module.info and misc_module.module file, right? We're going to write a simple query that returns the most recent blog nodes for the 'test_nodecarousel' nodecarousel. (That's the nodecarousel name - since you can have multiple nodecarousels on a site, they have different names.) The misc_module.module file would contain:

<?php
/**
* Implements hook_nodecarousel().
*/
function misc_module_nodecarousel($nodecarousel_name, $start_position, $number_of_nodes, $nid) {
  if (
$node_carousel_name == 'test_nodecarousel') { // Is this the nodequeue I want to return nodes for?
   
$nodes_result = array(); // This is my array for returning the nodes.
   
$query = "SELECT nid FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"; // This query gets me the items I'm looking for.
   
$result = db_query_range($query, $start_position, $number_of_nodes); // Here I'm using $start_position and $number_of_nodes to get the correct point in the list
   
while($row = db_fetch_object($result)) {
     
$node = node_load($result->nid);
     
$nodes_result[] = $node;
    }
    return
$nodes_result; // return the nodes.
 
}
  return array();
}
?>

Yes, if you were doing the most recent blog items, you would use the other settings, but I needed a simple example.

 
 

Drupal is a registered trademark of Dries Buytaert.