WordPress: Building Themes from Scratch Using Underscores

Video: Working with archive.php

With the index template looking exactly how we want it, we have to make sure our other archive templates also match this design. So if you go to the front page of your site and scroll down until you find this post called markup HTML tags and formatting and click on the link to the markup category. You'll see that we have a bit more work to do. At the top of each archive page you have the archive title, telling you what archive you're currently looking at. And you also have an optional description for some of the archives. So for instance, tags and categories can have custom descriptions.

Working with archive.php

With the index template looking exactly how we want it, wehave to make sure our other archive templates also match this design.So if you go to the front page of your site and scroll down until you findthis post called markup HTML tags and formattingand click on the link to the markup category.You'll see that we have a bit more work to do.At the top of each archive page you have thearchive title, telling you what archive you're currently looking at.And you also have an optional description for some of the archives.So for instance, tags and categories can have custom descriptions.

Now we need to apply styling to these elements to make them lineup with the rest of the content and appear part of the overall design.If I right-click on any of these elements and inspect the code, you'll see thatthis whole header section is wrapped in a header tag with the class page header.And within that we have an H1 with a classpage title and also a div with a class taxonomy description.So these are the elements we need to apply styles to.The first thing you have to do, is get thesection here to shift over and appear above the main content.

And if you think back, we've.Previously had a similar situation with another element.It was the paging navigation that was on the bottom of our pages.So now we can borrow the same styles that we applied tothe paging navigation to get the header here to look the same.The paging navigation style I'm talking about,was placed inside layouts and content side bar.And here, if I scroll all the way to the bottom, you'll see this is thestyle paging navigation and it applies a backgroundof white and then some padding around the box.

So here, I'm going to append another class to it, so I'll say page-header,comma and save it, and then go and reload my page and see what happened.So now my page header has the background it needs but of course it'snot aligning properly and that's because we need to add the alignment as well.And just like with this rule set here, we alsohave a previous rule set we created for all our alignments.And it has two components.It starts off here at the top wherewe have entry header, entry content, and so on.

So here I can add in, page-header, and this first rulesets the full width, and also aligns it to the center.And then we have the additional, media query that weuse to align the content to the right on medium-sized screens.So here I'll add my as well.Save one more time, and reload the page.And now my page header aligns properly.Now that I have the page header in the placeI want, I need to go back into my codesnippets and apply some styles to this description, because Iwant the description to appear not part of the content.

I want to apply a different font family to it.And do some other things like remove the border at the bottom here.So if you go back to the code snippetsyou'll find a custom rule, just for taxonomy description.I'll copy that out, and this time I'm going togo to style dot css and add it in.And here I need to find my index pages section which I remember is right over 11.And then I'll place it right before here.So taxonomy description.I'm setting padding on the top and the bottom.Setting the font family.Setting the font to italicized and adding a border at the topand the bottom, so that the description is clearly separate from the title.

Save style dot css.Reload the page.And now my taxonomy description is separated from the title.Now that it looks right, we need to make sure that the output of thissection is correct because if I now go and switch to something else, let's say April.2014.You'll see it says, Month: April 2014, And the underscore's theme has applied a bunchof predefined text that comes out dependingon what type of archive page you're in.And you may want to change this text to something else.

In particular.I don't like the wording for categories becauseit just says the name of the category.It doesn't tell you that this is a category.All of this is controlled from the archive dot php template.And if you go into archive dot php, and you scroll down a little bit,you see, here we have the page header, followed by the H1 class page title.And within that class, we have a longlist of conditional statements that test for different scenarios.So here we have.Is category, and then it just displays the title of the category.If it's a tag, it displays the title of the tag.

If it's the author, then you get author colon and the author name.It it's day, you get day colon and date and so on and so on.And then we have a long section here for Asides,and Galleries, and Images, and all the other post formats.And at the very bottom, we have a fallback that just says, Archives.So I want to change these elements, so thatthey output exactly the text that I want.In particular I want categories to say, category, and then the category name.So if you go to the codes scroll down, you'llsee here I've made an alternate version of this top text.

So what happens now is, instead of just saying the category name.This function says if we are on a category, it'll say post in the, and thenspell out the category and title, and thencategory, so I'll say post in the markup category.Same with the tags and I've also added some slight changes to some ofthe other texts, and I've removed all of the post formats we don't need.So I'm going to copy this out, and thengoing to replace everything from this php delimiter here,all the way up to the start here, and when I save this, and go back and reload thepage, so you'll remember this is a category page,the title will say pause in the markup category,and I notice that there is a small errorhere, so I'm just going to go in and change that.

So that there's a space after the m here and probably the same for the tagand now we have more informative titles forour category pages, regardless of which page we're on.

There are currently no FAQs about WordPress: Building Themes from Scratch Using Underscores.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.

Already a member ?

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships.
Learn more

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.

Sign up and receive emails about lynda.com and our online training library:

new course releases

newsletter

general communications

special notices

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

new course releases

newsletter

general communications

special notices

Here’s our privacy policy with more details about how we handle your information.