calendar.class.php v2.6

copyright © 2008 Jim Mayes
licensed under: Creative Commons Attribution-Share Alike 3.0 License

This class may not be used for commercial purposes without written consent.

Visit Style Vs. SUBSTANCE for information and updates

New Features

Link Only Specified Dates

Previously, the $link_days property allowed for either all days to be links ($link_days = 1), or to not have days link at all ($link_days = 0). Version 2.5 adds a third option to link only dates supplied in the $highlighted_dates array. Set $link_days = 2 and only your higlighted days will be links.

View Example

Formatable Day Linking

Previously, it was possible to set the destination URL of day links by assigning $link_to. The date would then be automatically appended to that URL in the format ?date=Y-m-d. Version 2.5 adds the property $formatted_link_to which accepts a string containing formatting options valid to PHP's date function. This allows the calendar to be used with site utilizing "cruft free urls".

View Example

Specify Start of Week

A commonly requested feature is the ability to designate the day of the week for weeks to start with. The property, $week_start accepts a numeric value representing the day of the week on which to start the week. Valid ranges are 1 = Monday thru 7 = Sunday. Setting $week_start = 1 for example will begin weeks on Monday.

***Because versions before 2.6 contained a display bug the old property $week_start_on has been removed and replaced with the new $week_start property. $week_start follows the ISO-8601 spec (1 = Monday thru 7 = Sunday). The old property did not (0 = Sunday thru 6 = Saturday). The old property was removed to purposely break backwards compatibility and force use of the new property.

View Example

Basic Usage Examples

Example 1 - Simple Calendar Output

By default, calendar.class.php will output the current month with today's date marked with a CSS class (.today) ready for you to style

View Example 1

Example 2 - Specified Month

calendar.class.php allows you to display a specific month by providing the just a month and year.

View Example 2

Example 3 - Specified Date

Provide a full date in YYYY-MM-DD format and calendar.class.php will output the correct month with the specified date marked with a CSS class (.selected) ready for you to style.

View Example 3

Example 4 - Hilighted Dates

calendar.class.php will accept an array of dates to mark on the calendar with a hilighted CSS class. You can use the default class name (.highlighted) or specify your own.

View Example 4

Example 5 - Days as Links

calendar.class.php can make each day on the calendar a link with the date appended to the URL as a variable named "date". This behavior is turned on by default but can be turned off. You may also specify the URL that the days link to and calendar.class.php will append the "date" variable to the URL you supply.

View Example 5

Example 6 - Localized Output

Version 2 of calendar.class.php now adds a localization layer to the calendar output. Use PHP's setlocale() function to output the calendar customized for your locale.

View Example 6

Advanced Usage Examples

Example 7 - Previous, Current and Next Months

calendar.class.php is flexible enough to easily display multiple month calendars with ease.

View Example 7

Example 8 - Full Year-at-a-time Calendar

Creating a full year-at-a-time calendar.class.php is easily accomplished with a simple PHP loop.

View Example 8