Community Documentation

Upcoming events

Last updated April 17, 2006. Created by munga on April 15, 2006.
Edited by cel4145. Log in to edit this page.

The "upcoming events" block doesn't allow to display upcoming events by category.

Assuming that you event nodes are associated with a vocabulary, this snippet displays
the next three events for every category.

<?php
$limit
= 3;
$time = time() - (2 * 60 * 60);

function
get_events ($tid, $limit, $time) {
   
$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, n.type, n.status, n.moderate, e.event_start FROM {node} n INNER JOIN {event} e ON n.nid = e.nid INNER JOIN {term_node} t ON t.nid = n.nid AND t.tid = %d WHERE n.status = 1 AND n.moderate = 0 AND e.event_start >= %d ORDER BY event_start"), $tid, $time);

    while ((
$node = db_fetch_object($result)) && $limit) {

        foreach (
module_implements('event_edit_upcoming') as $module) {
         
$function = $module .'_event_edit_upcoming';
         
$function($node);
        }
       
$ctype = module_invoke('flexinode', 'load_content_type', substr($node->type, 10));
       
$node->typename = ($ctype->name ? $ctype->name : $node->type);

        if (
$node->status) {
         
$items[] = theme('event_upcoming_item', $node);
         
$limit--;
        }
    }
    if(!
$items) {
        return;    
    }else {
         return
theme("event_upcoming_block", $items);
    }
}

$vid = 2;
$result = db_query("SELECT tid, name FROM {term_data} WHERE vid = %d", $vid);

while (
$t = db_fetch_object($result)) {
   
$events = get_events($t->tid,$limit,$time);
    if (
$events) {
        print
"<h2> $t->name </h2>";
        print
$events;
    }
}

print
theme('event_more_link', 'event');
?>

About this page

Drupal version
Drupal 4.7.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.