Essential Grid in Category, Archive, Search, Taxonomies

A little outside of scope but I think you guys have this figured out. I love using essential grid rather than the blog and in an old post https://theme.co/apex/forums/topic/custom-archive-and-search-index-page-with-essential-grid/ you showed how to make searches, archives and categories display the grid in place of masonry so everything didn’t have to be modified. I tried using the sample code and it doesn’t look like much has changed, but maybe I’m not doing it right. Do I use that code in the _index.php file in framework/views/global or somewhere else? Do I copy that file to my pro child theme?

Really appreciate the help, that really does make an amazing integration with pro and essential grid.

Thank you!!!

Hello There,

Thanks for posting in! You will have to create a new file and insert the code. You will then save the file as _index.php ad upload it in your child theme’s folder wp-content/themes/pro-child/framework/views/global/

Hope this helps. Please let us know how it goes.

Reporting back! If this would work like it seemed to for the other user this would be the greatest thing ever! However, I created an _index.php file and put it in that location and nothing seems to happen, no changes, no results for categories or archives come back as an essential grid. You can see the code of that file below, and I used the alias for my essential grid. Any tips? I probably missed something small. The beauty of this is that if you can incorporate it like this with X-Pro it would be such an easy way to create a beautiful blog area!

<?php

// =============================================================================
// VIEWS/GLOBAL/_INDEX.PHP
// -----------------------------------------------------------------------------
// Includes the index output.
// =============================================================================

$stack = x_get_stack();

if ( is_home() ) :
  $style     = x_get_option( 'x_blog_style', 'standard' );
  $cols      = x_get_option( 'x_blog_masonry_columns', '2' );
  $condition = is_home() && $style == 'masonry';

elseif ( is_archive() ) :
  $style     = x_get_option( 'x_archive_style', 'standard' );
  $cols      = x_get_option( 'x_archive_masonry_columns', '2' );
   $condition = is_archive() && $style == 'masonry';
if(is_tag()) $my_posts = get_posts(array('tag' => get_query_var('tag')));
else if(is_author()) $my_posts = get_posts(array('author' => get_query_var('author')));
else if(is_date()) $my_posts = get_posts(array('m' => get_query_var('m'))); 
else $my_posts = get_posts(array('cat' => get_query_var('cat')));
 
$my_post_ids = array();
 
foreach($my_posts as $post) {
   array_push( $my_post_ids, $post -> ID );
}
elseif ( is_search() ) :
  $condition = is_search() && $style == 'masonry';

   if(is_tag()) $my_posts = get_posts(array('tag' => get_query_var('tag')));
   else if(is_author()) $my_posts = get_posts(array('author' => get_query_var('author')));
   else if(is_date()) $my_posts = get_posts(array('m' => get_query_var('m'))); 
   else $my_posts = get_posts(array('cat' => get_query_var('cat')));
 
   $my_post_ids = array();
 
   foreach($my_posts as $post) {
     array_push( $my_post_ids, $post -> ID );
   }

endif;

?>

<?php if ( $condition ) : ?>
<?php echo do_shortcode('[ess_grid alias="lab-posts" posts="'.implode(',', $my_post_ids).'"]'); ?>
    <?php else : ?>
      <?php if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post(); ?>
      <?php x_get_view( $stack, 'content', get_post_format() ); ?>
    <?php endwhile; ?>
  <?php else : ?>

      <?php x_get_view( 'global', '_content-none' ); ?>
    <?php endif; ?>
 <?php endif; ?>

<?php pagenavi(); ?>

Hi There,

Above this line try to display some text to make sure that the condition is correct:
<?php echo do_shortcode('[ess_grid alias="lab-posts" posts="'.implode(',', $my_post_ids).'"]'); ?>
Maybe something like this:
<?php echo ' This text will display if the condition is true else nothing'; ?>
If you see that specific text on the frontend that means condition is correct and then essential grid shortcode result is blank. If not, visit the logic for $condition and see where it fails. Usually, I tried to display different text on different parts of the code to see where my logic fails.

Hope this helps.

Thanks Lely. It doesn’t output, but based on my stack the condition seems to be correct. This would be amazing, but I’m not sure why the code would work for someone else? Here’s the latest I’m using where I added a condition for categories. It’s so weird. Perhaps something has changed with the theme since people were using this to display an essential grid for the blog? I’m using the essential grid that came with the theme and it works perfectly wherever else I use it? Thank you in advanced for your help, I know this is a little outside scope but you guys are really great at getting users fixed up. Thank you thank you!

[code]<?php

// =============================================================================
// VIEWS/GLOBAL/_INDEX.PHP
// -----------------------------------------------------------------------------
// Includes the index output.
// =============================================================================

$stack = x_get_stack();

if ( is_home() ) :
$style = x_get_option( ‘x_blog_style’, ‘standard’ );
$cols = x_get_option( ‘x_blog_masonry_columns’, ‘2’ );
$condition = is_home() && $style == ‘masonry’;

elseif ( is_archive() ) :
$style = x_get_option( ‘x_archive_style’, ‘standard’ );
$cols = x_get_option( ‘x_archive_masonry_columns’, ‘2’ );
$condition = is_archive() && $style == ‘masonry’;
if(is_tag()) $my_posts = get_posts(array(‘tag’ => get_query_var(‘tag’)));
else if(is_author()) $my_posts = get_posts(array(‘author’ => get_query_var(‘author’)));
else if(is_date()) $my_posts = get_posts(array(‘m’ => get_query_var(‘m’)));
else $my_posts = get_posts(array(‘cat’ => get_query_var(‘cat’)));

$my_post_ids = array();

foreach($my_posts as $post) {
array_push( $my_post_ids, $post -> ID );
}

elseif ( is_category() ) :
$style = x_get_option( ‘x_category_style’, ‘standard’ );
$cols = x_get_option( ‘x_category_masonry_columns’, ‘2’ );
$condition = is_category() && $style == ‘masonry’;
if(is_tag()) $my_posts = get_posts(array(‘tag’ => get_query_var(‘tag’)));
else if(is_author()) $my_posts = get_posts(array(‘author’ => get_query_var(‘author’)));
else if(is_date()) $my_posts = get_posts(array(‘m’ => get_query_var(‘m’)));
else $my_posts = get_posts(array(‘cat’ => get_query_var(‘cat’)));

$my_post_ids = array();

foreach($my_posts as $post) {
array_push( $my_post_ids, $post -> ID );
}

elseif ( is_search() ) :
$condition = is_search() && $style == ‘masonry’;

if(is_tag()) $my_posts = get_posts(array(‘tag’ => get_query_var(‘tag’)));
else if(is_author()) $my_posts = get_posts(array(‘author’ => get_query_var(‘author’)));
else if(is_date()) $my_posts = get_posts(array(‘m’ => get_query_var(‘m’)));
else $my_posts = get_posts(array(‘cat’ => get_query_var(‘cat’)));

$my_post_ids = array();

foreach($my_posts as $post) {
array_push( $my_post_ids, $post -> ID );
}

endif;

?>

<?php if ( $condition ) : ?> <?php echo do_shortcode('[ess_grid alias="lab-posts" posts="'.implode(',', $my_post_ids).'"]'); ?> <?php echo ' This text will display if the condition is true else nothing'; ?>
<?php else : ?>
  <?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
  <?php x_get_view( $stack, 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php else : ?>
  <?php x_get_view( 'global', '_content-none' ); ?>
<?php endif; ?>
<?php endif; ?> <?php pagenavi(); ?>[/code]

Hi there,

Judging the code you have the $condition section is working only if the style of the blog is set to be masonry. So kindly go to X > Launch > Options > Blog and set the style to Masonry. If you are using Pro, the menu item will be Pro > Launch > Theme Options > Blog.

Thank you.

It is set to that. So close! It would be awesome if we could get this to work - imagine an X pro site with EG blog, search and archives! Any other ideas? It really does look like all is correct but I don’t know?

Hello There,

At this moment, the code will not work because it is messed up. Please have it indented and properly address each of the condition. The if-else statement needs a closing statement too. The correct way should look like this for example:

if ( is_home() ) :
  $style     = x_get_option( 'x_blog_style' );
  $cols      = x_get_option( 'x_blog_masonry_columns' );
  $condition = is_home() && $style == 'masonry';
elseif ( is_archive() ) :
  $style     = x_get_option( 'x_archive_style' );
  $cols      = x_get_option( 'x_archive_masonry_columns' );
  $condition = is_archive() && $style == 'masonry';
elseif ( is_search() ) :
  $condition = false;
endif;

Looking at your code, it is difficult which line should be displayed with this condition or what should be displayed when the condition is true or false.

If you are going to nest the if statement, please have it something like this:

if ( condition1 ) :
  // some statements

  if ( another condition ) :
    // do something here
  else :
    // do something else
  endif; 

elseif ( condition2 ) :
  // some statements

  if ( another condition ) :
    // do something here
  else :
    // do something else
  endif; 

elseif ( condition3 ) :
  // some statements
endif;

Hope this make sense.

Thank you so much. I think that old code may not be applicable to X Pro like it was X - I think the better way to go is what the essential grid people already have figured out (I didn’t realize this):

https://www.themepunch.com/faq/auto-populate-grid-for-blog-pages-with-the-loop-advanced/

The question is, which file do we add that to so that our blog, archives, tags, authors and search bring back our blog grid? Do we copy index to views/global in the child theme and somehow add it there?

If that piece of code really does that it would be amazing - could we really bypass all of the standard blog stuff and replace it all with essential grid by adding that? Any tips on how to paste it in the file appreciated.

Hi,

You can try changing the entire code of your global/_index.php file with this.

<?php

// =============================================================================
// VIEWS/GLOBAL/_INDEX.PHP
// -----------------------------------------------------------------------------
// Includes the index output.
// =============================================================================

$stack = x_get_stack();

if ( is_home() ) :
  $style     = x_get_option( 'x_blog_style' );
  $cols      = x_get_option( 'x_blog_masonry_columns' );
  $condition = is_home() && $style == 'masonry';
elseif ( is_archive() ) :
  $style     = x_get_option( 'x_archive_style' );
  $cols      = x_get_option( 'x_archive_masonry_columns' );
  $condition = is_archive() && $style == 'masonry';
elseif ( is_search() ) :
  $condition = false;
endif;

?>

<?php if ( $condition ) : ?>

  <?php x_get_view( 'global', '_script', 'isotope-index' ); ?>

  <div id="x-iso-container" class="x-iso-container x-iso-container-posts cols-<?php echo $cols; ?>">

    <?php if ( have_posts() ) : ?>
    <?php $my_post_array = array(); ?>
      <?php while ( have_posts() ) : the_post(); ?>
        <?php if ( $stack != 'ethos' ) : ?>
          <?php x_get_view( $stack, 'content', get_post_format() ); ?>
        <?php else : ?>
          <?php x_ethos_entry_cover( 'main-content' ); ?>
        <?php endif; ?>
        <?php $my_post_array[] = $post->ID; ?>
      <?php endwhile; ?>
<?php echo do_shortcode( '[ess_grid alias="even_grid_adams" posts='.implode(',', $my_post_array).']' );?>
    <?php else : ?>
      <?php x_get_view( 'global', '_content-none' ); ?>
    <?php endif; ?>

  </div>

<?php else : ?>

  <?php if ( have_posts() ) : ?>
  <?php $my_post_array = array(); ?>
    <?php while ( have_posts() ) : the_post(); ?>
      <?php x_get_view( $stack, 'content', get_post_format() ); ?>
      <?php $my_post_array[] = $post->ID; ?>
    <?php endwhile; ?>
    <?php echo do_shortcode( '[ess_grid alias="even_grid_adams" posts='.implode(',', $my_post_array).']' );?>
  <?php else : ?>
    <?php x_get_view( 'global', '_content-none' ); ?>
  <?php endif; ?>

<?php endif; ?>

<?php pagenavi(); ?>

Further customizations from here would be getting into custom development, which is outside the scope of support we can offer. If you need more in depth changes, you may wish to consult with a developer. X is quite extensible with child themes, so there are plenty of possibilities.

Thanks for understanding.

AMAZING! You have the BEST support ever. I know this was a little outside the scope of normal service so thank you even more. I pasted that (replacing the name of my grid) and I deleted this line:

<?php x_get_view( $stack, 'content', get_post_format() ); ?>

which prevents it from outputting both the regular blog and the grid blog at the same time - is it okay that I deleted that line only, will that mess something else up?

and now searches, category lists I created, the blog page (which is really a pro page with a grid element) all return the grid just as I had hoped! Thank you so much, you can check it out here with the menu showing links to different categories:

https://www.advancedbiology.com/lab/

You might also notice that I was able to implement the parallax header you pointed me to in another thread that now makes my article images appear up top with the title and excerpt so it mimics all of my other page menu graphics. You’re the best!!!

You’re welcome and thank you for your kind words! :slight_smile:

Is there any way to make this work for The Grid Plugin too?

Thanks

Hi there,

Unfortunately, we will not be able to implement the code for you we can only give you suggestions. We did not test the code we will suggest so that will only be a starter. Instead of the essential grid section in the code you need to use The Grid:

<?php echo do_shortcode('[the_grid  name="lab-posts" posts="'.implode(',', $my_post_ids).'"]'); ?>

But I am not sure if it will work as I don’t know if The Grid shortcode accepts posts as the argument.

I am sure you will understand that this is a highly customized thing and we can not offer additional support.

Thank you.

Hey man, Thanks for the reply. I try it but its doesn’t work. I understand this is outside of your support area.

Thanks

You’re always welcome.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.