Sage 8.5 -> Mansory Grid for Blog

Heya,

I am trying to add a mansory - .grid class to the “main” class - just for the “blog” page.

What wld be the best way to achieve that?

I`ve tried a custom wrapper that didn´t work out its always using the base.php.

I ve added the “.grid” class to the “body” via body-class function - didn´t work well cause I need that add to the main class .

I wld be thankful for an advice!

WordPress conditional tags are an obvious candidate here. I’m typing from my phone, but the gist would be to put a conditional tag to check if you’re on a blog or archive page directly in the <main class="classes and conditional statements go here"> tag.

Another option would be to fire Masonry using a different selector that’s already in place on the site. I haven’t implemented Masonry in a while but from their wrbsite it looks like you could fire it from any selector.

Hope this helps.

Thanks,

I didi it like this in base.php

      <main class=<?php 

        if (is_home()) {
          print "\"main grid\"";
        }
        else{
          print "\"main\"";
        }

      ?>>

is there a more elegant solution :)?

How about this?

// main.js
$('.blog .grid').masonry({
  // options
});

…and maybe in your assets function -

  if(is_home()) {
    wp_enqueue_script('masonry', '', ['jquery']);
  }
1 Like