Build Your Own Business Website header image

Community Library Website – Part 19 – Add Post Meta and Taxonomy Information to the Post Display

Difficulty Level -

Whoops, you've found some premium content!

Watch the opening clip of this video to preview it,
the full video is available to paid members.

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.

Community Library Website – Case Study Part 1 – Site Organization
Community Library Website – Case Study Part 2 – Create Custom Post Types
Community Library Website – Case Study Part 3 – Custom Post Type Configuration
Community Library Website – Case Study Part 4 – Custom Taxonomy Decisions – Theory
Community Library Website – Case Study Part 5 – Custom Taxonomy Decisions – Practical Application
Community Library Website – Case Study Part 6 – Incorporating Existing Data Into the Project
Community Library Website – Case Study Part 7 – Creating Hierarchical Custom Taxonomies
Community Library Website – Case Study Part 8 – Creating Non-Hierarchical Custom Taxonomies
Community Library Website – Case Study Part 9 – Creating Custom Post Meta
Community Library Website Case Study – Part 10a – Restore the Database Using BackupBuddy
Community Library Website Case Study- Part 10 – Creating Custom Post Meta – Continued
Community Library Website – Part 11 – Importing Existing Data to the Website
Community Library Website – Part 12 – Prepare Existing Data for import by the CSV Importer plugin
Community Library Website – Part 13 – Import Existing Data Using the CSV Importer Plugin
Community Library Website – Case Study Part 14 – Date in Permalink Configuration
Community Library Website – Part 15 – Importing Images
Community Library Website – Part 16b – Final Data Import
Community Library Website – Part 17 – Add Thesis Post Meta to Custom Post Type
Community Library Website – Part 18 – Add WordPress 3.0 Menus
Community Library Website – Part 19 – Add Post Meta and Taxonomy Information to the Post Display
Community Library – Part 20 – Add topics and audience to book display
Community Library – Part 21 – Display the Rest of the Post Meta in the Post
Community Library Website – Part 22, Create the Permalink Structure
Community Library – Part 23 – Remove Custom Post Meta from Post Display
Community Library Website – Part 24, Add Taxonomy and Post Meta Data to the Teaser
Community Library Website – Part 25, Add Taxonomy Data to the Teaser
Community Library Website – Part 26, Adjust the Teaser Styling Using Design Options
Community Library Website – Part 27, Styling the Teaser Using CSS
Community Library Website – Part 28 – Fine Tune the Teaser Display
Community Library Website – Part 29, Designing a Custom Catalog Page
Community Library Website – Part 30, Using a Query String in a URL
Community Library Website – Part 31, Adding Custom WordPress Menus
Community Library Website – Part 32, Add Custom Menus to the Catalog Page
Community Library Website – Part 33, Add Another Custom Menu to the Catalog Page
Community Library Website – Part 34, Troubleshooting Custom Menus
Community Library Website – Part 35, Add Styling to WordPress Menus
Community Library Website – Part 36, Add HTML Markup to WordPress Menus
Community Library Website – Part 37, Add WordPress Menus to Archive Pages
Community Library Website – Part 38, Add and Style a List of Tags
Community Library Website – Part 39, Add a Search Box to the Sidebar
Community Library Website – Part 40, Add Links to the Sidebar
Community Library Website – Part 41, Add Taxonomy Drill Down Browsing
Community Library Website – Part 42, Custom Loop to Display Custom Post Types
Community Library Website – Part 43, Simple Custom Query
Community Library Website – Part 44, Custom Taxonomy Query
Community Library Website – Part 45, Add Thesis HTML Structure to Teasers 
Community Library Website – Part 46, Display Posts from the Last 60 Days
Community Library Website – Part 47, Custom Loop If Have Posts
Community Library Case Study – Part 48, Increase the Number of Posts that Display on the Custom Catalog
Community Library Website – Part 49 – Naming Conflicts in Custom Taxonomies
Community Library Website – Part 50 – Find and Replace Semi-colons in the Database
Community Library Website – Part 51 – Modify Taxonomy Names Directly in the Database
Community Library Website – Part 52 – Sort Posts by Meta Value
Community Library Website – Part 53 – Show the Term Label Only when a Term Exists
Community Library Website – Part 54 – Sort Archive Posts by Meta Value
Community Library Website – Part 55 – Add Sort Order to Custom Taxonomy

Video Transcript

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.

0 Comments… add one

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
THIS IS A LIMITED TIME OFFER!
Subscription Options
0 comments… add one

Leave a Comment