I am in the process of building a Church website, and my client requested an upcoming events page.
In the next few days, I want to share with you the requirements I was given and the solution that I came up with, so you can build one, too!
Let’s begin.
Some Bad Solutions
I’ve seen current events displayed on other Church website that are using WordPress. The common solution is to create an Events category and filter according. If they’re publishing a blog, too, they simply block the Events category from the blog post listings, and on the dedicated Events page, they only query the Events category.
Sure, this works. However, depending on how well loops have been dealt with, it doesn’t look polished. I’ve seen Church Event pages that allowed comments, or the annoying “Comments are Closed.”
Yuck.
These are some of the problems you see from a user standpoint. I know there are some ways to work around this, by creating the proper page template and custom loops. But what about the Admin? Who wants to weed through all those posts to find Events
Moreover, what happens after the Event.
The Requirements
Here are the requirements I am using to create a solid, simple Events Page:
- Dedicated Events listing in WordPress Admin.
- List Events on the Events Page in ascending order, based on Event date, not date posted.
- Automatically stop displaying Events on the Events Page that have already occurred.
Are you ready?
Let’s Begin
First, we need to create a Custom Post Type. This is where the WordPress magic really starts to happen.
A Custom Post Type will get us a dedicated listing of Events, and can easily be found on the main WordPress Admin menu.
To create my Custom Post Types, I like to use this WordPress Custom Taxonomy & Post Type Generator. For this purpose, we only need the Custom Post Type generator.
Here’s the code:
[cc lang=”php”]/* Events */
add_action( ‘init’, ‘register_cpt_event’ );
function register_cpt_event() {
$labels = array(
‘name’ => _x( ‘Events’, ‘event’ ),
‘singular_name’ => _x( ‘Event’, ‘event’ ),
‘add_new’ => _x( ‘Add New’, ‘event’ ),
‘add_new_item’ => _x( ‘Add New Event’, ‘event’ ),
‘edit_item’ => _x( ‘Edit Event’, ‘event’ ),
‘new_item’ => _x( ‘New Event’, ‘event’ ),
‘view_item’ => _x( ‘View Event’, ‘event’ ),
‘search_items’ => _x( ‘Search Events’, ‘event’ ),
‘not_found’ => _x( ‘No Events found’, ‘event’ ),
‘not_found_in_trash’ => _x( ‘No Events found in Trash’, ‘event’ ),
‘parent_item_colon’ => _x( ‘Parent Event:’, ‘event’ ),
‘menu_name’ => _x( ‘Events’, ‘event’ ),
);
$args = array(
‘labels’ => $labels,
‘hierarchical’ => false,
‘description’ => ‘Upcoming Church events.’,
‘supports’ => array( ‘title’, ‘editor’, ‘excerpt’, ‘thumbnail’, ‘custom-fields’, ‘revisions’ ),
‘public’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘menu_position’ => 5,
‘show_in_nav_menus’ => true,
‘publicly_queryable’ => true,
‘exclude_from_search’ => false,
‘has_archive’ => true,
‘query_var’ => true,
‘can_export’ => true,
‘rewrite’ => true,
‘capability_type’ => ‘post’
);
register_post_type( ‘event’, $args );
}[/cc]
Now, you can place this into your theme’s functions.php file, or you can create your own Functionality Plugin. Personally, I’m using the functionality plugin.
Now that our Event Custom Post Type is created, we’ll look at how to lay the foundation to display it in our theme, in Part 2.
Craig Allen says
Sweet! I’ve been doing it the “less than ideal” way for awhile and needed a better solution. Looking forward to the completion of this series.
…and thanks!!
Eric Dye says
Sweet! Great to hear!
Jeremy Smith says
Is this a better solution that a custom page template? You could literally display as you said, an events category on a single page, and choose not to display comments or other parts of the loop, all in one page without creating custom post types. (Obviously, this is assuming that what the New Post offers is sufficiant for your event and you do not need to have additional parts added.)
Eric Dye says
Using the custom post type will help keep things organized on the admin side. Plus, if you list blog post categories, for instance, you have to block the Events category. It would also throw all your Events into your blog RSS feed, something you may want to keep separated. There are just a few more reasons one might want to keep Events separated from regular Posts, in addition to those I said before.
🙂
Jack says
I’m interested to follow this. I just started planning to write my own plugin for this today!
Eric Dye says
Awesome.
#WINNING!