WP SITES

3082 Coded Tutorials & 284 Plugins

CSS Grid Columns In Genesis

In this tutorial, i’ll provide several different methods which enable you to display any type of posts archive in columns.

You can use the CSS rules in any theme however you may need to modify it slightly.

CSS Grid

CSS Grid enables you to use percentages, pixel values or fractional units fr like you see in the following CSS rule.

.content {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-gap: 20px;
}

The above CSS generates exactly what you see in the following screenshot.

The above CSS rule can also be written using the repeat() CSS function like this :

.content {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-gap: 20px;
}

You can also write the CSS using percentages like this :

.content {
    display: grid;
    grid-template-columns: 33% 33% 33%;
    grid-gap: 20px;
}

And, you could also uses pixel values.

Media Queries

You can use the following CSS rule which displays each post ( grid item or fractional unit ) in 1 column on smaller screens

@media only screen and (max-width: 960px) {

.content {
        grid-template-columns: 1fr;
        grid-gap: 0;
    }

}

Other Methods

The following methods control the width of the .post class. You can also use these CSS rules with the .entry class or filter the post class and add your own custom class.

Here’s an example showing a category archive page displaying 3 columns of featured images using the content sidebar layout in Genesis.

Grid Columns - Content Sidebar Archive Page Genesis

Here’s the code which makes the above happen:

.archive .post {
     display: inline-block;
     width: 33.333333333333%;
     padding: 1%;
}

.archive .entry-meta,
.archive .entry-title,
.archive .entry-header:after,
.archive .entry-content p {
    display: none;
}
Note: You will need to view the source code and find the correct body class to replace if you want to use this solution on pages which don’t use the .archive class.

Some themes will need the padding and some will not so you can remove it in this case.

Here’s what the Columns look like using the full width template for the Twenty Fourteen default theme for WordPress.

2014 full width archive grid

Here’s the CSS code:

.archive .post {
     display: inline-block;
     width: 28%;
     padding: 2%;

}

.archive .entry-meta,
.archive .comments-link,
.archive .entry-content p {
    display: none;
}

.archive .entry-title {
    font-size: 25px;
}

Here’s the result of using the CSS code below and full width layout option on the News Pro theme by StudioPress:

full width columns

And here’s the code you’ll need to add to your child themes style.css file before the start of the Media Queries.

.archive .post {
     display:inline-block;
     width:33.333333333333%;
}

.archive .entry-meta,
.archive .entry-title,
.archive .entry-header:after,
.archive .entry-content p {
    display: none;
}

4 Column Grid

Here’s another way to create archive page columns for your featured images using a different CSS method.

.archive .post {
    float: left;
    width: 25%;
}

.archive .post:nth-of-type(4n+1) {
    clear: left;
}

.archive .entry-meta,
.archive .entry-title,
.archive .entry-content p {
    display: none;
}

And here’s the result tested on Genesis:

4 column grid layout

Different Themes – Code Variations

Clearly, different themes are coded different with different values for different classes.

You’ll notice in the Twenty Fourteen themes CSS that i have added a value to change the entry title. You will need to customize this value as all titles are different lengths which may mess up the display. Or you can simply hide the titles altogether in most themes.

The CSS will also be different on some themes depending of whether you use the full width layout or content sidebar layout so you will need to modify the code based on which theme you’re using.

Media Queries are not included in this tutorial.

Other Options

15 responses to “CSS Grid Columns In Genesis”

  1. How to customize a Genesis Blog

    […] is by far the easiest tutorial for creating a gallery for your category pages. This tutorial is for any WordPress theme, not just Genesis. The grid will actually display on any […]

  2. André Avatar
    André

    Brad Dalton,

    I´m using WordPress 3.9 – Modern Portfolio Pro Theme

    i´ve tried to find where can paste the code, but no had idea…

    https://my.studiopress.com/themes/modern-portfolio/

  3. Hi,
    Should say on the home page using featured-content /not posts!

    T

    1. Brad Dalton Avatar
      Brad Dalton

      Thats not what the solution provides. It assumes you are using the normal archive page loop.

      1. Thanks. Was trying to find basic CSS coding to create columns (genesis) for featured posts and this seems to be the closest I could find. So as a stating point as you mentioned archive becomes home and I guess .post becomes .featured-content and so on?

        .home .post {
        display: inline-block;
        width: 28%;
        padding: 2%;

        }

  4. Hi,
    How do you do this on a home page with posts?
    T

    1. Brad Dalton Avatar
      Brad Dalton

      Use .home as your class rather than .archive.

  5. hi brad,

    have you done tutorial for NEWS PRO:….. create FULL WIDTH header?

    thx

    mel

    1. Brad Dalton Avatar
      Brad Dalton

      Try this:

  6. Krystyn Avatar

    Thank you for this. Any suggestion how to get the image to be above the post title? Right now I’ve got the post title coming first, then the image..I’d like to reverse it.

    1. Brad Dalton Avatar
      Brad Dalton

      Use this and change the hook position and 3rd parameter.

      You could also add the code to a custom category archive template.

      The archive-portfolio.php template in Executive Pro would be the best to copy.

      1. Krystyn Avatar

        I feel like I’m missing something. I’ve copied the archive-portfolio.php template over from executive pro and renamed it category.php. I renamed all references from executive to Beautiful.

        Now, how do I get a category to actually use that template? Make a page called “category #1”, but I can’t change the post type to “category” so how do I get it to populate the posts from category 1? What am I missing?

        1. Brad Dalton Avatar
          Brad Dalton

          No need. WordPress will use it because of the template hierarchy in this order of priority.

          Template file used to render a Category Archive Index page

          1. category-{slug}.php – If the category’s slug were news, WordPress would look for category-news.php
          2. category-{id}.php – If the category’s ID were 6, WordPress would look for category-6.php
          3. category.php
          4. archive.php
          5. index.php

          Name it category-slug.php replacing slug with the category i.d or name for your category if you only want it to replace one category archive page as shown above.

          You might want to remove some of the code inside the file if its the archive-portfolio.php template.

          1. Krystyn Avatar

            Also, if I’m going to do the same thing across the board for the categories, why do I need the custom page, if just the css works?

          2. Brad Dalton Avatar
            Brad Dalton

            You don’t.

Leave a Reply

New Plugins