Alright.
By now, you should have created your Event Custom Post Type and edited and created a Loop specifically made for your soon-to-be-created WordPress Events Page.
Like I said, yesterday, WordPress basically flows like this:
- Page > Page Template > Loop
I like to start building from the end, so today, we are going to build our awesome Page Template.
Custom Page Template
First, open up your Template’s index.php file.
Immediately rename the file to page-event.php, so you don’t wreck your index.php Template file.
Like so many times, this is going to depend on the Theme you’re using; however, this should more than likely be the case.
What you want to look for is the line of code that pulls the regular Loop, since you will be pulling the Loop you created, yesterday. But let’s not get ahead of ourselves.
Let’s first change our new page-event.php into an official Custom Page Template and add (or replace) this first line of code to this:
[cc lang=”php”][/cc]
This will make the file you are editing available on the Page Attributes Template pull-down menu in the WordPress Admin.
Event Loop
Look through your php file and look for the Loop.
It should be a line of code like this:
[cc lang=”php”]get_template_part( ‘loop’, get_post_format() );[/cc]
Again, blah-blah-blah, depends on your template, but it’s the “loop” that’s key.
I’ve taken my code in Standard Theme, above, and changed it to:
[cc lang=”php”]get_template_part( ‘loop-event’, get_post_format() );[/cc]
As you can see, the ‘loop-event’ is accessing the Loop you made, yesterday.
Cool, right?
Nice Touch for No Events
While we’re at it, let’s do a little something nice for when there are no Events to list.
Look through your code, and you’ll see something like this:
[cc lang=”php”]
[/cc]
This is how it looks in Standard Theme, but most any other Themes will clearly have error text for when there are no posts to render.
This is how I changed it:
[cc lang=”php”]
[/cc]
It’s nothing major, but it makes an Events page look intelligent instead of broken when there are no Events listed.
Tomorrow
The Page Template is almost done!
But, first, we have to Query our Event Custom Post Type and setup the parameters/requirements I stated in Part 1. We’ll dive into that, tomorrow. 😉
Go ahead and save your file, you don’t want to lose your changes!
[…] of code and not leaving anything hanging behind that will jam things up and break it.Tomorrow, we’ll pull from this Loop into action, as we build the Event Page Template! About Eric […]