Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #141521
    danielmoutou
    Participant

    Hello X Generation! 🙂
    I have one more is-it-possible-question: is it possible… to randomly display the Portfolio items? I have the latest Ethos stack with WP 4.0 and I have set up a child theme.

    Thank you for reading,
    Cheers,
    Daniel

    #141648
    Paul R
    Moderator

    Hi Daniel,

    Thanks for writing in!

    To randomly display the Portfolio items

    Create file _index.php in wp-content\themes\x-child-ethos\framework\views\global
    and copy the code below into that file.

    
    <?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;
    if(is_post_type_archive( 'x-portfolio' )){
    global $query_string;
    query_posts($query_string . '&orderby=rand');
    }
    ?>
    
    <?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 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(); ?>
    

    Create file _portfolio.php in wp-content\themes\x-child-ethos\framework\views\global
    and copy the code below into that file.

    
    <?php
    
    // =============================================================================
    // VIEWS/GLOBAL/_PORTFOLIO.PHP
    // -----------------------------------------------------------------------------
    // Includes the portfolio output.
    // =============================================================================
    
    $stack    = x_get_stack();
    $entry_id = get_the_ID();
    $paged    = ( is_front_page() ) ? get_query_var( 'page' ) : ( ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1 );
    $cols     = get_post_meta( $entry_id, '_x_portfolio_columns', true );
    $count    = get_post_meta( $entry_id, '_x_portfolio_posts_per_page', true );
    $filters  = get_post_meta( $entry_id, '_x_portfolio_category_filters', true );
    
    switch ( $cols ) {
      case 'One'   : $cols = 1; break;
      case 'Two'   : $cols = 2; break;
      case 'Three' : $cols = 3; break;
      case 'Four'  : $cols = 4; break;
    }
    
    ?>
    
    <?php x_get_view( 'global', '_script', 'isotope-portfolio' ); ?>
    
    <div id="x-iso-container" class="x-iso-container x-iso-container-portfolio cols-<?php echo $cols; ?>">
    
      <?php
    
      if ( count( $filters ) == 1 && in_array( 'All Categories', $filters ) ) {
    
        $args = array(
          'post_type'      => 'x-portfolio',
          'posts_per_page' => $count,
          'paged'          => $paged,   
          'orderby'        => 'rand',
        );
    
      } else {
    
        $args = array(
          'post_type'      => 'x-portfolio',
          'posts_per_page' => $count,
          'paged'          => $paged,     
          'orderby'        => 'rand',  
          'tax_query'      => array(
            array(
              'taxonomy' => 'portfolio-category',
              'field'    => 'id',
              'terms'    => $filters
            )
          )
        );
    
      }
    
      $wp_query = new WP_Query( $args );
    
      ?>
    
      <?php if ( $wp_query->have_posts() ) : ?>
        <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
          <?php if ( $stack != 'ethos' ) : ?>
            <?php x_get_view( $stack, 'content', 'portfolio' ); ?>
          <?php else : ?>
            <?php x_ethos_entry_cover( 'main-content' ); ?>
          <?php endif; ?>
        <?php endwhile; ?>
      <?php endif; ?>
    
    </div>
    
    <?php pagenavi(); ?>
    <?php wp_reset_query(); ?>
    

    Hope that helps. 🙂

    #141896
    danielmoutou
    Participant

    It works beautifully, thank you so much! And at the same time, I can learn a few things by comparing the parent and the child files…
    Have a nice evening,

    Cheers,
    Daniel

    #142034
    Cousett
    Member

    Glad we were able to help. 🙂 Have a nice day.

    #377274
    theleoad
    Participant

    Is this solution still working? My use it in my Renew stack site?

    #377395
    Rupok
    Member

    Hi @theleoad

    You can try the solution. As your stack is different, you have to create different the file in a different directory – wp-content\themes\x-child-renew\framework\views\global (Re check the stack and name)

    Let us know how it goes.

    Thanks

    #377400
    Nico
    Moderator

    Hi There,

    Thanks for writing in.

    Upon checking the code above, it is still working. You can let us know if it is not working so we could take a closer look on your setup. Don’t forget to create a new thread so you could send us private details that only you and us could view.

    Thanks.

    #377965
    theleoad
    Participant

    Hi! It worked beautifully…

    I just need to tell you one thing: the child theme folder structure here for me is different. I installed the child theme this week, and there’s no such path as you mentioned above. These files I uploaded to wp-content\themes\x-child\framework\views\global.

    Thanks a lot for the great support!!

    #378305
    Friech
    Moderator

    Hi There,

    Yes, the x-child-renew or x-child-stackName is the old naming of the child theme, where different child theme for different stack. But the current version of child theme (x-child) is a kind of one for all stack.

    Glad we could help, Cheers!

    #709430
    kelleynunn
    Participant
    This reply has been marked as private.
    #709526
    Rupok
    Member

    Hi Kelley,

    Thanks for updating the thread. Make sure to create the file on proper directory structure. Your Child Theme directory is not same as the above user. Follow the above replies and make sure to create proper directory for the files.

    Cheers!

    #709556
    kelleynunn
    Participant

    Hey, ThemeCo!

    You were right– the issue was that I had not used the proper file structure. Instead, mine went to: /themes/x-child/framework/views/global.

    Thank you for your help, and for providing this code snippet!

    -Kelley

    #709810
    Jade
    Moderator

    You’re most welcome Kelley. 🙂

  • <script> jQuery(function($){ $("#no-reply-141521 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>