Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #307472

    Joel
    Participant

    Hi support:

    Link to website: here

    I have a question which I know is outside of scope, but was hoping to get some direction, I’m so close!

    I have set up Essential grid as my blog and archive index page. I did this by editing the global/ _index.php template in my child theme. However, whenever I input text in the search bar, no results ever show up. So I know I must have deleted something I shouldn’t have.

    Here is the code I’m trying to include in my global/_index.php…

    <?php
    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 );
    }
     
    echo do_shortcode('[ess_grid alias="blog page" posts="'.implode(',', $my_post_ids).'"]');
    ?>

    Here is the original global/_index.php…

    <?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';
    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 while ( have_posts() ) : the_post(); ?>
            <?php if ( $stack != 'ethos' ) : ?>
              <?php x_get_view( $stack, 'content', get_post_format() ); ?>         
     <?php x_get_view( 'content', 'search' );
            <?php else : ?>
              <?php x_ethos_entry_cover( 'main-content' ); ?>
            <?php endif; ?>
          <?php endwhile; ?>
        <?php else : ?>
          <?php x_get_view( 'global', '_content-none' ); ?>
        <?php endif; ?>
    
      </div>
    
    <?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(); ?>
    

    Can you give me some pointers as to what exactly I need to edit/delete in the original _index.php file?

    #307756

    Rue Nel
    Moderator

    Hello There,

    Thanks for writing in!

    Your changes will not work because you have modified the index.php which is being used as the base templates of the home, index, archives, category and search. Please retain the old index.php and insert your customizations inside the conditions. For example, in line:

    elseif ( is_archive() ) :
      $style     = x_get_option( 'x_archive_style', 'standard' );
      $cols      = x_get_option( 'x_archive_masonry_columns', '2' );
       
       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 );
       }

    And then in displaying the contents, you can replace this block of your code instead:

    <?php if ( $condition ) : ?>
       echo do_shortcode('[ess_grid alias="blog page" posts="'.implode(',', $my_post_ids).'"]');
    <?php else : ?>

    Having it this way, you just simply replaced masonry with essential grid without changing the default standard setting.

    Hope this make sense. Please let us know how it goes.

    #308169

    Joel
    Participant

    Thanks for the help! I’m not sure if I did this totally right, but here is how I updated my index.php…

    <?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() ) :
      
    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="blog page" 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(); ?>

    My Blog Index page and the Category Archive are pulling the Essential grids which is what I wanted. However, the search results pulls in the regular integrity blog format instead of the essential grid.

    Do I have to change anything else?

    Thanks for the support!

    #308316

    Rue Nel
    Moderator

    Hello There,

    Please add a condition if it is a search page:

    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;

    Hopefully the search page will display using the essential grid.

    Please let us know if this works out for you.

    #309997

    Joel
    Participant

    I’ve included my _index.php for others who might want to implement a similar solution. Blog and archives work perfectly and the search results pulls in the queries same as with no customizations, but not the essential grids. Another thing is that the Search Results Page does not use the masonry template, which is a bit disappointing. So my solution will be to include a search bar within my Essential Grid layout.

    If you guys have any other recommendations I’d be glad to implement and test. Thanks for the awesome support!

    <?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="blog page" 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(); ?>
    #310148

    Paul R
    Moderator

    Hi Joel,

    Your code looks good.

    Glad you were able to figure it out.

    Thanks for sharing.

    Have a nice day!

    #399212

    Malte K
    Participant

    What do i have to do, when i have custom post types? my custom post types will not show up.

    i edit the functions.php to add my custom post types to the archive but when i want to have essential grid to show my custom post types it is not working.

    // add custom types to archive
    function namespace_add_custom_types( $query ) {
    if( is_category() || is_tag() && empty( $query->query_vars[‘suppress_filters’] ) ) {
    $query->set( ‘post_type’, array(
    ‘post’, ‘nav_menu_item’, ‘ausstellung’
    ));
    return $query;
    }
    }
    add_filter( ‘pre_get_posts’, ‘namespace_add_custom_types’ );

    #399218

    Malte K
    Participant

    ah that was easy i just changed every where “get_posts” to ==> “query_posts” thats it. and now my custom posts are displaying too.

    #399382

    Prasant Rai
    Moderator

    You are most welcome 🙂 .

    #399791

    Malte K
    Participant

    ah but the search ist not working with custom post types, what do i have to change?

    #399794

    Thai
    Moderator

    Hi There,

    Please update this code a bit:

    // add custom types to archive
    function namespace_add_custom_types( $query ) {
      if( is_search() || is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
        $query->set( 'post_type', array(
          'post', 'nav_menu_item', 'ausstellung'
        ));
      return $query;
      }
    }
    add_filter( 'pre_get_posts', 'namespace_add_custom_types' );

    Hope it helps!

    #738855

    Malte K
    Participant

    it is still not working with essential grid. check the example: http://maltekebbel.de/?s=papier … what is wrong? now i got the x_get_view, but essential grid is not working. hm!?

    <?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 = query_posts(array('tag' => get_query_var('tag')));
       else if(is_author()) $my_posts = query_posts(array('author' => get_query_var('author')));
       else if(is_date()) $my_posts = query_posts(array('m' => get_query_var('m'))); 
       else $my_posts = query_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="archiv" 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(); ?>
    #739078

    Rue Nel
    Moderator

    Hello There,

    Thanks for updating this thread! Would you mind providing us the url of your site with login credentials so we can take a closer look at your custom template? This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

    To do this, you can make a post with the following info:
    – Link to your site

    – WordPress Admin username / password
    – FTP Hostname
    – FTP Username
    – FTP Password

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    Thank you.

    #768569

    Malte K
    Participant

    for custom taxonomies…

    
       if(is_tag()) $my_posts = query_posts(array('tag' => get_query_var('tag')));
       else if(is_tax('kuenstler')) $my_posts = query_posts(array('kuenstler' => get_query_var('kuenstler')));
       else if(is_tax('technik')) $my_posts = query_posts(array('technik' => get_query_var('technik')));
    
    #769265

    Rad
    Moderator

    Hi there,

    Would you mind providing the requested information?

    Thanks!