7 days of WordPress plugins, themes & templates - for free!* Unlimited asset downloads! Start 7-Day Free Trial
FREELessons: 22Length: 2.8 hours

Next lesson playing in 5 seconds

  • Overview
  • Transcript

3.4 The Content Pages (Part 2)

Hey, welcome back. In the previous lesson, I started writing this function for the post_meta. And as you can see, I got the sticky part done. Next up is the post author. So, we're gonna say get the post author. And inside, we start with this. printf and this will be quite a mouthful, so I'm gonna try to explain as we go along, so printf. The first thing that we got to do is a list item, just like the sticky post. So list item class meta author, okay. And let's close it. Now inside we're gonna have a link. And that link will open in an archive's page for that author. So, we're gonna say, a href, and I'm gonna put this, percent sign, 1$ s. And then rel is going to be author. Again to help with accessibility. And inside this anchor tag, I'm gonna put %2$s. Now these right here are, let's call them placeholders. They are used by the print functions to display a much larger string. So what I mean by that is this. If I were to put like 'String 1' here and then 'String 2' here. And then refresh. I'm gonna get. An anchor tag with the href string one and the content of string two. So basically, when this is rendered, this little bit will be replaced whatever is inside String 1, and this little bit by whatever is inside String 2. So now that we know how this works, I'm gonna do this. The href we can get it by the following function, get_author_posts_url and then we gotta tell this function which author ID to use. And for that we can use get_the_author_meta, ID. And get the author meta is a function that returns certain information about an author. And in this case we're just grabbing the id which in turn, we're sending to this function as a parameter. And this will get the href, which will be placed right here. And on top of this, we gotta wrap it In another function, esc_url, which will basically sanitize the returned value, so that we don't get any errors later on. And, on String 2, we gotta say the name of the author. Well, that's very simple, we just say get_the_author. And that's gonna return the name of the author. So now refresh. We have admin. And the link. It says WordPress 39 ms/author equals one. Okay, so that is the author. Next up is the date. So we're getting the date at which the post was written, and we start with this echo again. A list item. The class will be meta-date and inside we're going to put get the date. Save that, refresh, and there it is. That's the date, May 21st, 2014. Next up, the categories. So, the categories. You can do it like this. Create a new variable called $category_list, and that's going to be filled in with get the category list. And, this is a function that will return all the categories and then you can separate them with this little bit. And then we can do a check if $category_list, which basically means if we have any items in our $category_list. Then we can do an echo list item with a class of meta-categories, and then inside simply display the $category_list. Save, refresh and there it is. If we go about and creating a category test and we apply it to the testing posts, you'll see that. That now we have test and uncategorized for this post. Next is the tags. So, the tags is actually very similar to categories. So I'm just gonna copy this and paste it to save a bit of time. So, the tags. In here, instead of $category_list, I'm gonna have tag list basically. So tag list will be get the tag list and then if tag list then list item class meta tags, and then we display the tag list. Refresh, and let's go ahead and add a few tags. Gonna update it. And there it is. Now we can see that we have a comma here and that's not necessarily good because we can add another parameter here that's gonna tell to miss that comma. If there's only a single tag. So if we add multiple tags here. Let's see, tag two. Now we have tag two, comma, and then test. So simply add this little parameter, a blank space, to the get the tag list function. Next we have the comments link. So if we have any comments and the comment section is opened. Then we're going to display a link that's going to say how many comments we have and also will get us to the comment section in the post page. So let's start with this. If comments_open yeah then we're going to start with this echo list item and then close it. And in between, I'm gonna do an echocode for a span. The class of matter applied and then I'm gonna close the span. In between I'm gonna do this ,comments_popup_link, and this receives three parameters. The first one is for when we don't have any comments. So we gonna display a text like, leave a comment. So I'm gonna save this actually. I'm gonna mark it for translation. 'Leave a comment', 'alpha', and then the second parameter is for when there's one comment. So again, using the translatable string, 'One comment so far'. 'alpha' and finally we have one for when we have multiple comments, and that's gonna be view all. We can use the percent sign here to display the number of comments, so view all comments, 'alpha'. Let's save and let's refresh. Let's see, syntax error or unexpected on line 132. Okay, I forgot to close the if so andif right here. Save, refresh, and there it is. Leave a comment, because we don't have any comments on Testing, and one comment so far on Hello World. And finally, we have the Edit link. So, Edit link. The Edit link should only be displayed if the user is logged in. So, we're going to start with that check. If is_user_logged_in then, or actually, let's do it the old fashioned way. Then we're gonna echo a list item and close the list item. And in here I'm gonna say edit_post_link. First of all the title of the link which will be translatable as well. 'Edit' 'alpha'. And then the second parameter will be the container the link is gonna be wrapped into. So, we're gonna say here a 'span with a class of meta-edit' and then close that span. Okay, so refresh and there it is. That's the Edit link. If I'm gonna log out from here, this link won't be visible anymore. Okay, and that completes the post meta. So now, the header of our content here, is complete. Let's jump back to content php, yeah, so the entry header is complete. In the next lesson, I'm going to take care of the article content and also the article footer, so I'll see you there.

Back to the top