-
AuthorPosts
-
November 10, 2014 at 3:29 am #141521
danielmoutouParticipantHello 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,
DanielNovember 10, 2014 at 7:18 am #141648
Paul RModeratorHi 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. 🙂
November 10, 2014 at 11:32 am #141896
danielmoutouParticipantIt 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,
DanielNovember 10, 2014 at 2:49 pm #142034
CousettMemberGlad we were able to help. 🙂 Have a nice day.
September 2, 2015 at 9:10 pm #377274
theleoadParticipantIs this solution still working? My use it in my Renew stack site?
September 2, 2015 at 11:19 pm #377395
RupokMemberHi @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
September 2, 2015 at 11:21 pm #377400
NicoModeratorHi 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.
September 3, 2015 at 10:16 am #377965
theleoadParticipantHi! 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!!
September 3, 2015 at 5:53 pm #378305
FriechModeratorHi 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!
December 16, 2015 at 11:37 am #709430
kelleynunnParticipantThis reply has been marked as private.December 16, 2015 at 12:24 pm #709526
RupokMemberHi 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!
December 16, 2015 at 12:40 pm #709556
kelleynunnParticipantHey, 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
December 16, 2015 at 4:33 pm #709810
JadeModeratorYou’re most welcome Kelley. 🙂
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-141521 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
