This is the nineteenth in a series of live lessons on using WordPress and Thesis as a Content Management System (CMS). In this session we look at the display of the catalog item post. We want to add the subtitle and author name (post meta and taxonomy term) to the display of the post.
Rick: And then we are also going to add information to the listing and I’m just going to describe that I guess and then we’ll have to show it later. So one of the things that Pam and I worked on this weekend was what we want… when you select a book, what we want the page to look like when you select it. And so, what we want is the image to show up and then a nice, big title… this is a subtitle, this is the name of the author then the content. Then we’re going to add a couple of links. One, which is a mail to, that places the title of the book in the mail to request. And then the 2nd one is to read the review of this book. So if a book has been reviewed then this link shows up. And then we’ll have a listing of the topics and we’ll have the audience. And then at the bottom, we’ll have sort of the technical details – location, ISBN number, publication date, call number… that kind of stuff.
And then the other thing we’re going to do is change this information on these pages as they comment on the books so that people can make their own reviews of the book. And this is generally, what our post is going to look like when we’re finished with it. That’s what the custom post will look like. So the other thing I was going to try to accomplish today was adding this and this to that post type.
Okay so now what we’re going to do is we’re going to add the subtitle and we’re going to add the actual author’s name to this. And the way we do that is with a handy dandy function and this function has 2 parts. The first part is it’s going to get post meta and print that post meta. And the 2nd part is it is going to get the taxonomy terms and in particular, we are talking about the author taxonomy terms and print those.
Now, get post meta is very important, I think, super powerful function in WordPress and we’re going to take a look at the codex here for just a second. The syntax for get post meta is create a variable name and then equal it to get post meta. You got to call the post id and then the key for the post meta and then an answer to a question.
And so if we come over and look at ours, the first thing you have to do in this function is to take on the global variable post because we are processing this outside of the loop. And so, in order for this function to be able to access the post meta, it’s getting that post meta from this global variable post. So that’s the first thing we do is we make the post… we incorporate the global post variable.
The 2nd thing we’re doing is we’re saying… well, okay so if this is a single page which this display is, if this is a single post then byob subtitle equals get post meta. And so the first thing that we have to get is to tell it which post id we want and this form of the post id is the designation for post id inside the global variable post. So we’re saying in this post, get the post meta of subtitle…remember, that’s how we created it. And then return that information as a string and because we’re using just this text, that’s what we want to do. True here means return this post meta as a string of text. So that’s what we’re doing.
And then the 2nd part is the terms. Now this makes it… this function actually does a few other things besides just getting the information. Because what this function does is it gets the information and then it provides a link from that information to the archive page for that taxonomy term. And so, the taxonomy term we want to address is the author taxonomy. And we want it to display all of the terms in the author taxonomy for this given post. Let’s see, we’ll let it sit there. This is a very powerful tool also and there are other things that we can add to this string. We can see what kind of separator we want. If there’s more than one author, how would we like to separate it? If we don’t tell it, it’s going to default with a comma. We can also say how would we like the whole thing to be preceded? You know, we want to add a class to it or something like that. How would you like the whole thing to end? So there’s a bunch of other stuff we can do to this but for the time being, we’re just going to leave it nice and simple.
And then what we’re doing is we’re going to hook it to the Thesis hook after headline. And the Thesis hook after headline just happens right after the title of the post and we’re going to hook this function into that. Now Pam asks, “Am I going to get rid of the semi colons?” And the answer is yes but not today. So I just didn’t have time this week to get that whole thing figured out. So we’ll have to live with semi colons in the data today but the time we’re all finished, it’ll be all resolved.
So we’re going to save that function. We are going to upload that to the site and then come back over to the site and refresh it. and we’re almost there. You can see here’s the name of our author with a semi colon in it. If you click on that, this will bring us to the page that displays every book by that author. And now we just need to add the subtitle here. And so, that is something that I need to do back in custom… right here. And I need to echo that post meta so what we’re going to do is we’re going to say echo and then this variable… byob title. Put a semi colon there. See Pam, semi colons are your friend. Put semi colon there, save this, upload it and then test it.
Okay and so from the editors of Christian History magazine and then it’s got our name here, what we really want is this to drop down to a new name. So let’s do a little bit of HTML work here. We’re going to come back over to this and we are going to echo div class equals byob subtitle. And then single quote again… oh pardon me, I forgot the opening. So div class byob subtitle and then space period space. That concatenates these 2 things together. And then we’re going to do that one more time… dot and then open and closing quotes, closing div tag. And we may as well in fact, do an opening div tag for the author names so we’ll just say div class equals byob author names. And so now that’s going to put div tag in front of this and then we’ll just do another echo and it’s going to be a closing div. So now what we’re going to get is this is going to echo a div tag for byob subtitle then it’s going to put a subtitle in then it’s going to close the div tag and then it’s going to put the opening div tag in with a class of byob author names. Then it’s going to put the author names in then it’s going to put the closing div tag in. This will allow us to add CSS styling to this so we can you know, more clearly specify what’s happening here. So now, we’ll save this document and we will upload it and we will test it.
Okay so now you can see, from the editors of Christian History magazine and then the name and then the post date. And we could even choose not to show the post date in this if we wished. So if we come back to recent items for adults, we can look at another book and here is the Passion for Christ – The Visionary that Ignites Ministry. And then we’ve got Torrance, Thomas F. and James, B. It has 3 authors. This listing is an exception. Okay, well anyway, you can see what happens with the data.
And so we’ve gone a little bit long here. Pam did you have anything else you wanted to ask about this before we call it a day?
Pam: No, I would like to make sure that you remember to copy that last function code onto the forum. This is really helpful, thanks.
Rick: Yeah, you’re welcome. I will do that and we’ll just be working on this tonight.