on Event Calendar 3 for WordPress
I’ve recently been converting a client’s website over to WordPress. Since I haven’t spent much time developing my own blog on WordPress (a carpenter’s house, right?), I thought this would be an excellent opportunity to look into plugins and further customization.
One plugin that I found particularly useful for this client was Event Calendar 3. On her previous website, the client had a list of upcoming events and wished to have a similar setup on all pages of her blog. There are several calendar plugins available for WP, and I chose this one for a couple of reasons (and due to some Apache permission problems on her host with some of the other calendar plugins). First of all, it’s really easy to use and customize. I was able to set up the sidebar to display just the dates and titles of the events. Second, the events are all posts, so there’s no limitation on what additional information can be posted with the event.
Where I ran into problems with it is that WP treats the posts like any other blog entry. When I click on the category “Upcoming Events” it displays all the posts and the date they were posted, not the date the event is happening. Working with the default WP theme, my work around involved editing styles.css and archive.php:
First, I put the date as the first line in the post for all “Upcoming Events” posts. After that, there were two dates displayed, the first line was the post date and the second line was the event date. To format the second date to match the first, I grabbed the first paragraph of my post (in category “Upcoming Events”) using the first-child pseudo-class:
.category-upcoming-events .entry p:first-child{
color:#666;
}
I didn’t want to get rid of the post date for all categories, so my next step was to change the way archive.php displayed posts with the category “Upcoming Events.” In the WP Loop (the section that spits out all the posts), I edited the following section:
<h3 id="post-<?php the_ID(); ?>"><a title="Permanent Link to <?php the_title_attribute(); ?>" rel="bookmark" href="<?php the_permalink() ?>"></a></h3> <small></small>
The part between the <small> tags is the part that displays the time when the post was created. WP has a handy built in boolean function in_category() that returns true if the current post has the category indicated inside the parentheses. A trick I use all the time to save on code and headaches in PHP is using an IF statement and exiting PHP before my ‘if true’ statement so as to avoid having to use echo or print, and then going back into PHP and closing the if statement after the HTML, like so:
if(foo == bar){
?>
Hello World!
}
?>
Using this style in archive.php, I check the current post to see if it isn’t in the category “Upcoming Events,” and provided it’s not, I let php go ahead and echo the time the post was created. Otherwise, it just continues without echoing the time. Like so:
<h3 id="post-<?php the_ID(); ?>"><a title="Permanent Link to <?php the_title_attribute(); ?>" rel="bookmark" href="<?php the_permalink() ?>"></a></h3> <small></small>
This is all great and dandy, but my next project in this is to display the events in chronological order, in case a last minute event is added to the schedule. Stay tuned.

Leave a Reply