Start learning with our library of video tutorials taught by experts. Get started

WordPress: Building Responsive Themes

Configuring the index page with Masonry


From:

WordPress: Building Responsive Themes

with Morten Rand-Hendriksen

Video: Configuring the index page with Masonry

Now that we have jQuery Masonry hooked into our theme, it's time to apply it to the index page to create an index page with a Masonry layout. But before we do that, let me explain exactly what we are going to do. When I designed the Anaximander theme, I had a plan for two different index page layouts, so it's clear to the visitor where they are. On the front page, so the regular index or the blog index, I want to use Masonry to lay out the content in three boxes, one next to the other.
Expand all | Collapse all
  1. 4m 5s
    1. Welcome
      1m 4s
    2. Using the exercise files
      1m 27s
    3. What you should know before watching this course
      1m 34s
  2. 8m 36s
    1. What is responsive design?
      4m 16s
    2. The different faces of WordPress on mobile
      1m 55s
    3. Exploring the finished Anaximander theme
      2m 25s
  3. 9m 38s
    1. Getting and installing the Anaximander theme
      1m 53s
    2. Configuring basic theme options
      7m 45s
  4. 23m 51s
    1. Deciding what screen sizes to design for
      4m 11s
    2. Thinking responsively: Designing for many different screen sizes
      6m 23s
    3. Visualizing content realignment for better markup
      4m 35s
    4. Designing menus
      4m 52s
    5. Adding responsive images and videos
      3m 50s
  5. 26m 8s
    1. What are media queries and how do they work?
      4m 18s
    2. Exploring CSS3, progressive enhancement, and graceful degradation
      3m 27s
    3. Understanding best practices for media queries
      3m 57s
    4. Creating a responsive frame
      5m 12s
    5. Customizing media queries with the Chrome Developer Tools
      5m 28s
    6. Taking device width into account
      3m 46s
  6. 11m 1s
    1. Resizing the site title and the description
      8m 22s
    2. Adding media queries to the header
      2m 39s
  7. 11m 22s
    1. Making the menu responsive
      3m 35s
    2. Creating a different menu design for small screens
      7m 47s
  8. 19m 22s
    1. Making a responsive single-post layout
      6m 11s
    2. Making images responsive
      4m 37s
    3. Making videos responsive by including FitVids
      8m 34s
  9. 7m 45s
    1. Making the sidebar responsive
      5m 10s
    2. Hiding sidebars on mobile
      2m 35s
  10. 7m 28s
    1. Dealing with footer widgets
      5m 11s
    2. Adding navigation links that return to the top of the page
      2m 17s
  11. 12m 54s
    1. Using FlexSlider to create a responsive slider
      6m 2s
    2. Creating a loop to show sticky posts in a featured slider
      6m 52s
  12. 24m 37s
    1. What is jQuery Masonry?
      3m 41s
    2. Installing jQuery Masonry
      4m 45s
    3. Configuring the index page with Masonry
      7m 0s
    4. Using CSS to finalize the Masonry layout
      6m 17s
    5. Adding media queries to the Masonry index
      2m 54s
  13. 9m 11s
    1. Exploring hidden features of the Anaximander theme
      5m 51s
    2. Where to go from here
      3m 20s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
WordPress: Building Responsive Themes
2h 55m Intermediate Aug 17, 2012

Viewers: in countries Watching now:

The many ways visitors access web sites, via mobile devices, tablets, and desktops, now requires sites to incorporate responsive design elements that adapt to different screen sizes and browsers. In this course, Morten Rand-Hendriksen demonstrates design strategies, best practices, and actual code examples for creating a responsive web site. The course covers layout, navigation, responsive video embedding, and content sliders. The final chapter shows how to create an index page with jQuery Masonry, a jQuery plugin that helps you create dynamic grid layouts.

Topics include:
  • What is responsive design?
  • Installing the Anaximander example theme
  • Deciding what screen sizes to target
  • Designing menus
  • Adding responsive images and video
  • Using CSS media queries to apply different styles
  • Handling sidebars on mobile displays
  • Dealing with footer widgets
  • Installing jQuery Masonry
Subjects:
Web CMS User Experience Blogs Responsive Design
Software:
WordPress
Author:
Morten Rand-Hendriksen

Configuring the index page with Masonry

Now that we have jQuery Masonry hooked into our theme, it's time to apply it to the index page to create an index page with a Masonry layout. But before we do that, let me explain exactly what we are going to do. When I designed the Anaximander theme, I had a plan for two different index page layouts, so it's clear to the visitor where they are. On the front page, so the regular index or the blog index, I want to use Masonry to lay out the content in three boxes, one next to the other.

But on all the archive pages--so Author archive, Regular archive, Category archive and Tag archive--I want to retain this regular type of index where one post stacks on top of the other and we have a regular sidebar. That means a) we're only applying Masonry to the index.php file and b) we have to retain the styling for this regular index. Looking at the index page, we can see what we need to do here. First, we need to get rid of the sidebar. We then need to reorganize the content itself to match the Masonry layout. And finally, we have to make sure that on the bottom here, our pagination stays on the bottom and works properly.

But just before we dive into the code, let me show you something that I have hidden inside this theme. If we select a single post here, you will see that there's this figure class "the-thumbnail" that's inside the code, and if you look at the code itself, you will see there's an image here, but it's hidden using the style over here, regular-index .the-thumbnail display set to none. If I turn that style off, you will see that each of these posts actually has a thumbnail attached to it.

The reason why I hid it is because right now it looks kind of weird and I only want to use that thumbnail image in the Masonry index. That's also why it's sized the way it is. But if you want to have these featured images on each of the posts also in regular indexes, all you have to do is find out style in the style sheet and take it away. Now let's get down to business. The first thing we need to do is get rid of the sidebar. I'll go to my theme, find index.php, open it in my editor and then if I scroll to the bottom, we find a call to the sidebar right here.

Now, because I'm not 100% sure I want to get rid of it yet instead of deleting the function altogether, I am simply going to comment it out, and by commenting it out inside the php delimiter, it won't get rendered in the page. If we were to place HTML comments on the outside of the php delimiter, this code would be rendered and then hidden in the HTML. But I want to just hide it all together. So I'll save that, reload my page, and the images disappear of course, because I still have the style, but more importantly, you see that my sidebar disappears, and that's what I want.

Now I need to hook Masonry into the content on my page so that Masonry can realign it. The way that works is I tell Masonry what content it should work with and then Masonry applies the necessary styling and the necessary code to that content. To find out what that content is, I'll use my Developer Tools to identify the containers that contain all of those content. And if we look here, you will see that on my index page, I have a section with an id called regular- index and I also have a divider with an id called regular-content and clicking on them, you can see that these are the two containers that create the space for the sidebar.

Now I said previously I want to retain this layout for the other index pages, meaning rather than going in and changing the styling for regular-index and regular-content, what I need to do is create new names for these ids so that I can apply new styling to them. But if I look closely, I see that the regular index id in the styling is the one that creates that extra space we need for the sidebar and regular-content just responds to that style. So I should be able to remove regular-content altogether without affecting our Masonry layout.

I simply don't need it. So I'll go into index.php and find regular-content right here and I'll comment this out and see what happens. And of course, when I comment out the beginning of a div, I also have to comment out at the end. It's down here. so I'll simply move this comment over so that it's gone, save index.php, reload it in the browser, and now my content spans all the way from left to right, which is exactly what I want.

The last thing I need to do is rename regular- index to something else so that we can create custom styles for it, and here we have a bit of a chicken-and-egg situation, because this is the id that we'll be targeting using Masonry, and if you look at the function you created previously in the functions.php, you will see that that name is already defined right here, because what we are doing is we are creating a small function that tells Masonry to handle the content inside the masonry-index ID. And what Masonry will do is it will find each item inside the masonry-index ID, and then the items with the index_post_container classes are the ones that are going to be reorganized by Masonry.

So what we need to do is change the name of the ID from regular-index to masonry-index. So I'll go in here, change it to masonry-index, and then I'll also change the comment that closes it, so I see where it is. I'll save it again, reload my page. The images will appear again because the styling that hid the images were applied to regular-index, but more importantly, if we look at one of these single posts again, you will see that each post now has this index_post_container class attached to it, and it's also set as a masonry-brick, meaning that now Masonry is handling each of these items.

If you paid very close attention, you will also notice one other thing. The pagination is all of a sudden up here. That's because the pagination is floating based on the overall content. So the last thing we need to do here is move the pagination out of this container altogether so it doesn't appear here, but rather, down at the bottom of the page. So to close-up, we'll go and find our pagination, which is right here, cut it out, and just place it outside the masonry-index section. Save it, reload the page, pagination is no longer here, and if we scroll down to the bottom, it appears at the bottom where it's supposed to be.

There are currently no FAQs about WordPress: Building Responsive Themes.

Share a link to this course
Please wait... Please wait...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

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.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed WordPress: Building Responsive Themes.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

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

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

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:

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:

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

   
submit Lightbox submit clicked