Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Throughout this course, I've been mentioning the dry development principles several times. And now you'll see the value of that approach. If you go to your front page, or to any of the archive pages, you'll see that even though we have yet to touch any of these templates, all the styling for the individual posts that are displayed within the archive pages already inherits all the styling we applied to the same posts in the single post template. So here we have the same typography. And the only thing we need to do for the index pages is change the layout ever so slightly and address issues like Meda content not displaying quite right and removing this content on the bottom in the footer for each post.
If you look back at the design for the index pages, you'll see that the, the display for each post within the index pages is a little bit different from what we had on a single post. First of all, we have that rasterized background and each post is wrapped inside a white box that's separated from the next with some margin. Each post has a smaller feature image at the top, and there's a Continue Reading link at the bottom of each post, you can jump to the next one. In addition, the very first post on the front page displays differently.
It has the full large featured image, and it also displays all the text content before saying Continue Reading. And in this chapter, we're going to look at all of this styling to make our index pages look as good as our single post. So we'll start out by applying the rasterized background and a white box around each post and also generally fixing the mark up for each of the posts on the index pages. So I'm going to open layouts and contents-sidebar and here you'll remember right at the top we have the site-content rule that sets that grey background color.
So here I want to add in that rasterized effect instead, and I'm going to use the same technique I used to add the rasterized effect behind the featured images. So I have that piece of code here in my code snippets. I'm just going to copy out the background declaration and replace just the color. So now we have a background color. And then a transparent SVG that goes on top that adds that rasterized effect. I'll save that and reload it in my browser just to test that it works. And it does. Now we have to wrap each of the individual posts in a white box and align that white box.
To do that, I first need to know where the content is coming from. So I'm going to go do index.php. And find out which template is controlling the actual content. And here if I scrolled down, it will see just like for the single post, we have a loop. In the index.php post, word press first asks are there posts available? And if there are posts, it goes, as long as we've got a post. Go and set the Kern post to the post. So it's basically looping through each of the individual posts one at a time and then displaying its content.
And the ways displaying its content is by using the template part called content. In then, get post format. So if we had different post formats, and apply them to each post, then we'd be able to pull different content templates for each post format. But, if you look at the current list up of content templates that we have, we have content none. Content page, content single and just content. So because we don't have any post formats files for content, we're going to use content.php, we're just a fallback.
Content.php is for amount of varied similarly to contentsingle.php, so here we are going to do the same changes and we're going to do them one at a time. So I'm going to start off by adding that box around each post. And I'm going to add the box inside the article ID, so that the article ID stays the same. So here I'm going to add a new div, with a class, index box. And the index box class is what's going to create the white border. Then I'll close my div at the bottom here, right before the end of the article tag.
And I'll just comment it so I know what it is. And now that I've created the index box class and divider, I need to also add in the styles for it. So I'm going to go back to content sidebar here, and scroll down right before my media queries. And here I'm going to add in the styles. And you can find the styles in the code snippets. So here you see we have, first the index box style, that sets the total width of the box, gives the box padding so that everything gets shifted in and we get nice padding around it. We set a margin on the bottom to 2 m's, to push the content down.
And then we set the background to white. I also have some additional styles to deal with just a block quotes because you'll remember we shifted the block quotes left and right and now I have to make sure that they retain a white background. And also that on larger screens when they are shifted out of the frame, they get padding either on the left or on the right, so that the text doesn't go flush with the edge of the box. So I'm going to copy out all of this, and paste it into my style sheet. Save it. Go back and reload my page. And now each of my individual posts are separated with a nice, white background.
And there's a split between them underneath. But the problem is, right now it's aligning to the middle. And that's because we have to now tell WordPress in the style sheet that we want to use this shifting motion we created previously. So if I go back to content side bar and I scroll down a bit, you'll remember that we have this selector here, entry header, entry content, entry footer, et cetera. And we used it to shift all the content to the right on screens that were between 1160 pixels and 1539 pixels.
So now I'm just going to add index box to this list. And this will apply the same styling and the content will now shift over and become fully responsive. Now that the box is displaying the way that we want, I'm going to add a couple of more changes. First, I'm going to clean up the mark up here. You'll remember on the top on the single post, we said written by themedemos on January 7th, 2012. And then we have the list of comments and also the Edit button. So I'm going to go to content.php and find that same section. And here we have class=entry-meta, my_simone_posted_on.
So here I want to add in the same code that I used, in the single templates. I'm going to go and get content single, find the same section. So here we have my Simone posted on, and I'm going to copy out the rest of the section here and just paste it in, so this would give me that comments link and leave a comment. Then, I also want to add the Edit button right up here. And I know that the Edit button is somewhere within this template. So I'm just going to scroll down until I find it, and it's right here, at the very bottom.
So, I'm going to cut out the Edit button, scroll back up again, and paste it in directly after the comments section. And then when I have all the meta content at the top, I'm going to scroll down and find the footer section and just remove everything that's in the footer section because we don't need any of it for the index template. Later we're going to add that Continue Reading button inside this footer. I'll save this template. Then go and reload my page again, and now you'll see it says written by themedemos, January 7th, 2012.
Leave a comment, and when I scroll to the bottom, we have nothing. So now we have all the formatting we need and there's just one more thing we need to do. Because you notice, the problem of written by themedemos and then no on and no dot after January 7th as returned. And that's because, if we go back to the original style sheet and go to the meta content, this is how we inserted the on and the period. We said, on screens when the max-width is 1319 pixels.
Then we insert on end period. The problem is on the index pages, we want to display this at all times and right now, it's only displaying on smaller screens. So here I'm going to reverse the process. So if you go to the cold snippets one last time, and you go to in style.css and copy out the little section here and replace your media query with that new section, I'll explain what happens. So here I've reversed the process, I've said on every page set post it on before to on, and post it on after to period.
And then, I'm going to find any screen that has the minimum width of 1320, that means any screen that is larger than 1320 that would be when we start shifting the meta content off to the left hand side. I want to take just the single posts and set both posted on before and posted on after to nothing. That way we get the single posts to display the content on the left hand side and this extra content is removed whereas on every single other page including all the index pages we always display it on and period.
So, I'll save that a final time and go and reload my front page. And now you see it says written by themedemos on January 7th, period. Leave a comment. And this happens regardless of what size the screen is. And if I go to the post itself and scroll down, you'll see where we are on the smaller screen, it says written by themedemos on et cetera, but if I scale this up. To a wide enough screen. When the meta content shifts to the right, the on and the period are removed. So now everything works exactly the way we want it. By making some careful changes to the content.php template, copying in elements we've already made, removing other elements, and applying styles, we now have an index template that looks close to the design.
And if you jump to another index, say category or archive, you'll see that our changes are being applied there as well. Dry development principles in action.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.