This is the 13th in a series on using WordPress and Thesis as a Content Management System (CMS). In this case study we are creating a community news site. We have created a static page to display our events sorted by the event date. Now we want to display the event date on the event teasers. In other words we are displaying custom post meta on the teasers.
Case Study Part 1- Community News Site, Custom Taxonomy vs Custom Post Types
Case Study Part 2 – Community News Site, Setting Up the Test Site
Case Study Part 3 – Convert Posts to Custom Post Types
Case Study Part 4 – Configure Permalinks for Custom Post Types
Case Study Part 5 – Install and Configure Thesis
Case Study Part 6 – Listing Custom Post Types on the Appropriate Page
Case Study Part 7 – Community News Site Future Refinements
Case Study Part 8 – Add Thesis Meta to Custom Post Types
Case Study Part 9 – Display Custom Post Types by Category
Case Study Part 10 – Create Category Display Order
Community News Case Study – Part 11 – Add Event Information as Custom Post Meta to Events
Community News Case Study – Part 12 – Create a Page with a Custom Loop to Display the Events Sorted by Date
Community News Case Study – Part 13 – Display Event Date on Teasers
Community News Case Study – Part 14 – Show Only Upcoming Events
Community News Case Study – Part 15 – Format the Display of the Date
Community News Case Study – Part 16 – Display Event Venue
So let’s go ahead and do that too. Let’s make sure we show the event date on this and to show the event date, we are going to use that get post meta feature, right? I think I’ve got some get post meta up here someplace… I don’t. So let’s just go..okay, get post meta. Get post meta, okay… look at the function reference so get post meta is the post id, the key and then we decide whether or not we want it as a string or if we want it as an array. So we’re going to say single with that so we’re going to say meta values. We’re just going to grab that code, copy… and then what we’re going to do is paste that code here for a moment and we’re going to create another function and this function is going to be… this function adds the date, adds the event date to the teaser. Okay add even date… you all recognize this from our community library. So add event date to teaser… okay and you may actually remember that we need global post because we need to get that global variable post and then we’re going to say, instead of meta values, we’re going to say event_date.
Okay, we’re going to do the easy version for a moment. Get post meta and then we’re going to say global post id, so that grabs the current… that grabs the post id of the teaser that we’re working on and then the key is going to event date and then single is single, I think. Let’s just double check that. Oh pardon me, it’s true is what it is, not single. I knew something didn’t look right… true.
Okay so we grab the meta value and now we are going to echo the meta value. We’re going to echo event date, semi-colon, echo event date and then we need to look at Thesis hook. Let’s go to Thesis hooks and let’s see, teaser, before teaser headline, before teaser box. Let’s go after teaser headline if I’ve got one here, after teaser headline, okay, that’s what it is… Thesis hook after teaser headline.
So add action Thesis hook after teaser headline and then add event date to teaser. Now some of you probably already recognize that we aren’t testing if there is a value and stuff like that. Right now, we’re not going to refine that right now. We’re just going to double check that this is working. So we’re going to upload, we’re going to come back over here and let’s try it.
Full events listing… so did I refresh that? I did refresh it. It didn’t show up so I’ve made another mistake here someplace. Thesis hook after teaser headline, add event to teaser, global post, event date, echo… let’s just make sure we’re getting there… hello. Let’s see, maybe I’m not getting the information the way I should. Refresh it, okay it does say hello so I’m not getting the date right.
I’m just going to look and see what we did on Community Library site. So I’m just escaping me here… yeah, tutorial site, library. I don’t know what it is. Obviously, I’m making some little error here and rather than fuss over it, let’s just see how we did it before.
So we come down here to subtitle and author name to the post heading and to the post teaser heading. Okay, global post, subtitle post, echo, get post meta subtitle equals get post meta… okay. So it looks exactly like we did it. Alright, event date equals get post meta post id event date and true, event_date, echo hello event date. Well, it can’t be as easy as that. I’m sure it’s not the capital letter here but let’s just try it. Maybe it is that easy, maybe it’s just… I was playing fast and loose. He shoots, he scores! That’s what it was.
Okay so 2011 08 28, 08 27, 08 14, 08 06. Okay so this is in… it’s being sorted in descending order. It was actually being sorted. Now what we want to do is sort it in the other direction. So let’s add this other sort, order by meta value, comma tab and then order… it was arrow asc. Save the document, upload the document, refresh the document. Okay and so now you can see, it’s in the opposite direction and 2011 5 01 so this one’s in the past, this one’s in the past. Those are in the past, Beach Party at Shill Show and this is in Seattle, okay great. Perfect.
Okay so we accomplish sort of our first task which was add the custom post meta to the post and then create a page that will take all of these events and sort them by that post meta.