Last updated 7 March 2008. Created on 7 March 2008.
Edited by pobster. Log in to edit this page.

/**
  * Creates a neat table of node titles
  * with a link to each one and 'submitted by...' information.
  * As this snippet uses the event module to sort entries you must make
  * sure to enable users to enter dates for the content type under "Show in event calendar:"
  *
  * $node_type must contain a valid content type NOT the content name.
  * To change the number of results listed, simply edit the $list_no number.
  *
  * This has been tested and works with Drupal 6.x
*/
  $node_type = 'results_page';  // I'm using a custom node type here to demonstrate you use the node type rather than the name
  $list_no = 25;
  unset($prev_year);
  $sql = "SELECT n.nid, n.uid, n.title, u.name, e.event_start
          FROM {node} n
            INNER JOIN {event} e ON n.nid = e.nid
            INNER JOIN {users} u ON n.uid = u.uid
          WHERE n.type = '%s'
          ORDER BY e.event_start DESC";
  $result = pager_query(db_rewrite_sql(sprintf($sql, $node_type)), $list_no);
  while ($node = db_fetch_object($result)) {
    $date = event_explode_date($node->event_start);
    if ($date['year'] != $prev_year) {
      $prev_year = $date['year'];
    }
    $output[$date['year']][] = array(array('data' => date("M jS", mktime(0, 0, 0, $date['month'], $date['day']))), array('data' => l($node->title, "node/$node->nid")), array('data' => '<em>Submitted by '. l($node->name, 'user/'. $node->uid) ."</em>"));
  }
  foreach ($output as $date['year'] => $table) {
    print theme('table', array(array('data' => '<h3>'. $date['year'] .'</h3>', 'colspan' => '3')), $table);
  }
  print theme('pager', NULL, $list_no);

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

leticia2602’s picture

/**
* (...) to enable users to enter dates for the content type under "Show in event calendar:" (...) 
*/

You need to have:

1- Installed the Event module (http://drupal.org/project/event)
2- Enabled this module in Administer/Modules section
3- Enabled one or more node types to be used with the event system (you can follow the indications of “INSTALL.txt” file, located in the Event module installation package)

Note 1: If isn't any event to show, you will get the warning

warning: Invalid argument supplied for foreach() in /includes/common.inc(1537) : eval()'d code on line 31.

You can avoid that declaring the variable $output as an empty array before the while statement.

Note 2: If you want to show the events related to nodes of type "page" you only have to put that value replacing the custom node type "results_page" in the code.

dineshbonn’s picture

I enabled the Php input format and when i create a page i put your code in my body of the page but it just display the code. is there any problem with the PHP input formats in drupal 6.10?..

Thank you

pobster’s picture

You actually need to select the php input format in your post, look just below the body field.

Pobster