Step by step guide to create an event listing with calendar block in Drupal 6
The contents of this guide is a Drupal 6 adaptation of the guide Step by step guide to create an event listing with calendar block in Drupal 7
Below are the list of steps to create an events listing with a calendar block which filters them.
Download and enable the required modules
- latest development build of calendar, date, ctools and views modules (tested with Views 2, but it should easily work with version 3 as well)
context and context_ui.features (needed by the feature module mentioned above).
(I didn't use Context and Features modules on my tests, if you want to use them you should follow and compare both guides.)
Create an Events content type
Go to Content management > Content types > Add content type (admin/content/types/add) and create one with the following settings:
- Name: Event
- Fields: Add a field of type Date, field name
event_dateand label Date(s). In the field configuration screen check the "Required" box and set "To Date" to Optional or Required. - Create three or four events at the "Add content" (
node/add/event).
Create a view to list events
Go to Site building > Views > Add new view (admin/build/views/add) and create a view showing nodes, Click on "Next".
Filter by the node type "Event"
Set the path of this page view to /events.
Add the following Arguments:
- Add the field "Date: Date (node)"
- At the "When the filter value is NOT in the URL", select "Provide default value" or "Display all values" as needed.
- If you wish "Provide default value", then select Current Date.
- At Date field(s), select "
Content: Date(s) (field_event_date) - From date". Don't select both From and To, only one of them is needed. - At Method, select "
AND". - Save.
Create a calendar block for events
- Clone the view "Calendar" into "Events calendar".
- Select the Block display and add a filter by content type so it only lists content of type "Event".
- Edit the Arguments so it looks exactly the same as the one we configured at the Events view. Warning: don't delete/add any arguments fields BUT edit the existing Date(node) field, selecting "
Content: Date(s) (field_event_date) - From date"!! It will avoid this error: Date argument not recognized as date in calendar view - Save.
Add the calendar block to the events view
Go to Site building > Blocks (admin/build/block), search for your Calendar block, add it to your region and to the correct events and events/* pages.
Link the calendar block links with the events view
Add the following code to your default theme. Remember to change "yourtheme" by the name of the default theme. This code shoud reside at sites/all/themes/yourtheme/template.php
/**
* Alters link url in calendar events block in order to filter events at /events
*
* @see template_preprocess_calendar_datebox()
*/
function wsava_preprocess_calendar_datebox(&$vars) {
$date = $vars['date'];
$view = $vars['view'];
$vars['day'] = intval(substr($date, 8, 2));
$vars['url'] = 'events/' . $date;
$vars['link'] = l($vars['day'], $vars['url']);
}
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion