Difficulty:Tricky in places

Version:Expression Engine 1.3.1: 20050812

Buy My Book!

Update July 2008: If you like these tutorials and would like to read more like these, except updated for ExpressionEngine 1.6 and with tons more information, tips, tricks and recommendations, check out my new book, Building Websites with ExpressionEngine 1.6. Available either directly from Packtpub.com or from your local online bookstore (such as Amazon), this book uses the same clear, step-by-step approach found in these tutorials and walks you from the basics of installing ExpressionEngine to everything you need to know to have an ExpressionEngine website you can be proud of. (No prior knowledge of ExpressionEngine assumed).

This tutorial assumes that you are already familiar with Expression Engine: you have got at least a basic site up and running, complete with templates and blogs. It also assumes that you understand that basics of CSS and HTML and have experimented with both. This tutorial is going to go through the basics of creating an events calendar. The functionality will be there, but I warn you now that it will look very boring when we are done: the homework (or another tutorial) will be to adapt and change the look and feel so that it fits in with your website and your needs.

Background Information

Most organisations have events, and a very visual way of keeping people up-to-date with events at your organisation is to have an events calendar on your website. A charity might want to publish when their fund-raising activities are happening, linking to other pages with more information about who can get involved and how to sign up. A gym might want to publish their swimming pool calendar, so that visitors can easily find out whether Saturday afternoon is open swim time, the advanced water aerobics class, or the under 5s inflatable session. A school might want to let parents know when the term begins, when the parent-teacher conferences are and when field-trips are scheduled.

Having a calendar can not only let people easily find out what they need to know, but can often give visitors information they didn’t know they needed to know. You go online to find out about water aerobic classes, and see a Salsa dancing class you’re much more interested in, but you never knew was offered.

Anyway, I’m sure if you’re reading this tutorial you already have an idea in mind for an events calendar. Now let’s find out how to make it a reality.

Instructions

If you're at the stage of writing an events calendar, I'm going to assume that you already have a CSS stylesheet and a basic look-and-feel for your website.

Duplicate an existing template...

Remove the unwanted content

...

<title>My Calendar of Toast</title>

...

<h1>My Calendar of Toast</h1>

...

The new title at the top of my browser window

Go to your admin page

Create a new Weblog Field Group

Name your fields

Add/Edit Custom Fields

Add a Custom Field

Define your Field

Define more fields

Select weblog management

Create new weblog

Name your weblog

Edit groups

Associate field groups

</div>

{exp:weblog:calendar switch="calendarToday|calendarCell" weblog="toast_calendar" start_day="sunday" show_future_entries="yes"}

<table class="calendarBG" border="0" cellpadding="6" cellspacing="1" summary="My Calendar" width="85%">

<tr class="calendarHeader">

<th><div class="calendarMonthLinks"><a href="{previous_path=toast_site/calendar}"><<</a></div></th>

<th colspan="5">{date format="%F %Y"}</th>

<th><div class="calendarMonthLinks"><a href="{next_path=toast_site/calendar}">>></a></div></th>

</tr>

<tr>

{calendar_heading}

<td class="calendarDayHeading">{lang:weekday_long}</td>

{/calendar_heading}

</tr>

{calendar_rows}

{row_start}<tr>{/row_start}

{if entries}

<td class='{switch}' align='center'><div class="calendardate">{day_number}</div></td>

{/if}

{if not_entries}

<td class='{switch}' align='center'>{day_number}</td>

{/if}

{if blank}

<td class='calendarBlank'> </td>

{/if}

{row_end}</tr>{/row_end}

{/calendar_rows}

</table>

{/exp:weblog:calendar}

<div id="footer">

First impressions of a calendar

Calendar CSS Template

<style type='text/css' media='screen'>@import "{stylesheet=toast_site/_css}";</style>

<style type='text/css' media='screen'>@import "{stylesheet=toast_site/calendar_css}";</style>

</head>

Add a reference to the new stylesheet

.calendarBG

{

background-color: #000;

}

.calendarBlank

{

background-color: #9DB7A7;

}

.calendarHeader

{

font-weight: bold;

color: #fff;

text-align: center;

background-color: #000;

}

.calendarMonthLinks

{

font-family: Arial, Trebuchet MS, Tahoma, Verdana, Sans-serif;

font-size: 11px;

font-weight: bold;

letter-spacing: .1em;

text-decoration: none;

color: #fff;

background-color: transparent;

}

.calendarMonthLinks a

{

color: #fff;

text-decoration: none;

background-color: transparent;

}

.calendarMonthLinks a:visited

{

color: #fff;

text-decoration: none;

background-color: transparent;

}

.calendarMonthLinks a:hover

{

color: #ccc;

text-decoration: underline;

background-color: transparent;

}

.calendarDayHeading

{

font-weight: bold;

font-size: 11px;

color: #fff;

background-color: #663300;

text-align: center;

vertical-align: middle;

}

.calendarToday

{

font-family: Arial, Trebuchet MS, Tahoma, Verdana, Sans-serif;

font-size: 12px;

font-weight: bold;

letter-spacing: .1em;

text-decoration: none;

text-align: left;

vertical-align: top;

color: #000;

background-color: #ccc;

}

.calendarCell

{

font-family: Arial, Trebuchet MS, Tahoma, Verdana, Sans-serif;

font-size: 12px;

font-weight: bold;

letter-spacing: .1em;

text-decoration: none;

text-align: left;

vertical-align: top;

color: #666;

background-color: #fff;

}

.calendarCell a

{

color: #000;

text-decoration: underline;

background-color: transparent;

}

.calendarCell a:visited

{

color: #000;

text-decoration: underline;

background-color: transparent;

}

.calendarCell a:hover

{

color: #ccc;

text-decoration: underline;

background-color: transparent;

}

.calendarEvent

{

padding: 0em;

background-color: #fff;

vertical-align: top;

text-align: left;

border: 1px solid gray;

font-family: Arial, Trebuchet MS, Tahoma, Verdana, Sans-serif;

font-size: 10px;

text-decoration: none;

color: #000;

margin: 0em;

}

.calendarEvent a

{

text-decoration: none;

display: block;

}

.calendarEvent a:hover

{

color: #000;

background-color: #ccc;

text-decoration: none;

}

.calendarEvent a:visited

{

text-decoration: none;

}

First impressions of a calendar

Your first calendar event

Pick a date for your first calendar event

Your 2nd calendar event

Your 3rd calendar event

My calendar detail template

Remove the unwanted content

...

<title>Event Information for my Calendar of Toast</title>

...

<h1>Event Information for my Calendar of Toast</h1>

...

The new title at the top of my browser window

</div>

{exp:weblog:entries weblog="toast_calendar" limit="1" show_future_entries="yes"}

<h2>{entry_date format="%l %j%S %F %Y"}: {event_time}</h2>

<h3>{title}</h3>

<h4>{event_location}</h4>

{event_info}

{/exp:weblog:entries}

<div id="footer">

A calendar event

...

{if entries}

<td class='{switch}' align='center'>

<div class="calendardate">{day_number}</div>

{exp:weblog:entries weblog="toast_calendar" year="{segment_3}" month="{segment_4}" day="{day_number}" limit="5" orderby="event_time" show_future_entries="yes"}

{if event_url}

<div class="calendarEvent">

<a href="{event_url}" title="Go to the event's website">

{event_time}<br />

{title}<br />

<i>{event_location}</i>

</a>

</div>

{/if}

{if event_url == ""}

{if event_info == ""}

<div class="calendarEvent">

{event_time}<br />

{title}<br />

<i>{event_location}</i>

</div>

{/if}

{/if}

{if event_info}

<div class="calendarEvent">

<a href="{url_title_path=toast_site/calendar_detail}" title="Go to the event's website">

{event_time}<br />

{title}<br />

<i>{event_location}</i>

</a>

</div>

{/if}

{/exp:weblog:entries}

</div>

</td>

{/if}

...


Note that my toast calendar is not a good example of this problem, since it has very few months with any entries, not matter what the URL looks like.

My currentyear template

<a href="{path=toast_site/calendar/<?php echo date("Y",time()); ?>/<?php echo date("m",time()); ?>}" title="Monthly Calendar">My toast calendar link!</a>


Got something to add? Add your comment to the 4 already made

Written by Leonard on Sunday 11th December 2005