Tagged: x
-
AuthorPosts
-
October 20, 2016 at 6:42 am #1223749
DariyaParticipantHi Team,
I have searched the archive but could not find a similar question.
How can I make my featured posts in Carousel to appear “random”? Right now they appear in the same ‘consecutive’ order (i.e. the newest first and the older ones last), but I would like them to appear randomly. And no, I cannot use the “random” feature instead of “featured”, because I need to have full control over which posts appear in carousel (we have some posts without pictures and I don’t want them to appear in carousel).
Thanks so much in advance!
Daria
October 20, 2016 at 9:45 am #1223952
RahulModeratorHey There,
Thanks for writing in!
To make the post carousel random, head over to Appearance > Customize > Ethos > POST CAROUSEL > Display and select the option Random.
You can even make your posts to Carousel by marking its option under the current post. See attached!
Hope this helps!
October 20, 2016 at 10:51 am #1224069
DariyaParticipantHi Rahul,
Sorry your answer is incorrect (or maybe you did not understand my question unfortunately).
The “Featured” Carousel posts are the ones you can manually select/unselect/ decide to feature in the carousel bar. Yes, you can select them as shown on your screenshot. But here’s the issue with this option – they are shown in a static, consecutive order – from newest to the oldest one. They are not randomized, they always show up the same in the carousel bar.
The “Random” Carousel posts are the ones that are shown in a random order but the problem with this option is that ALL posts are shown – including posts without pictures. Therefore there is no manual control/oversight with this option.
What I need is the cross between the two: I would like to use the “featured” posts but in a “random” (not static/ consecutive) order.
Does this make sense?
Thanks so much!
October 20, 2016 at 1:54 pm #1224301
RupokMemberHi Daria,
Sorry for the confusion. So you want to show the featured posts but randomly, right? Unfortunately it’s not possible. You can show either the Featured posts or all posts in random. You should set the exact number of post as featured that you are setting to show as “Post per page” – http://prntscr.com/cwsutl
So if you set 7 post, then the one will be ignored and that’s how it works.
Hope this makes sense.
October 20, 2016 at 2:06 pm #1224313
DariyaParticipantHi Rupok,
Thanks. Can you please advise why is it not possible? I am sure there is a code for that. Perhaps something similar to the below code I got from your team before (this code was for another feature than had to do w/Carousel):
Thank you!
<?php
// =============================================================================
// VIEWS/ETHOS/_POST-CAROUSEL.PHP
// —————————————————————————–
// Outputs the post carousel that appears at the top of the masthead.
// =============================================================================GLOBAL $post_carousel_entry_id;
$post_carousel_entry_id = get_the_ID();
$is_enabled = x_get_option( ‘x_ethos_post_carousel_enable’ ) == ‘1’;
$count = x_get_option( ‘x_ethos_post_carousel_count’ );
$display = x_get_option( ‘x_ethos_post_carousel_display’ );switch ( $display ) {
case ‘most-commented’ :
$args = array(
‘post_type’ => ‘post’,
‘posts_per_page’ => $count,
‘orderby’ => ‘comment_count’,
‘order’ => ‘DESC’
);
break;
case ‘random’ :
$args = array(
‘post_type’ => ‘post’,
‘posts_per_page’ => $count,
‘orderby’ => ‘rand’
);
break;
case ‘featured’ :
$args = array(
‘post_type’ => ‘post’,
‘posts_per_page’ => $count,
‘orderby’ => ‘date’,
‘meta_key’ => ‘_x_ethos_post_carousel_display’,
‘meta_value’ => ‘on’
);
break;
}
/* remove all posts without thumbnail */
$args[‘meta_key’] = ‘_thumbnail_id’;
$args[‘meta_compare’] = ‘EXISTS’;?>
<?php if ( $is_enabled ) : ?>
<ul class=”x-post-carousel unstyled”>
<?php $wp_query = new WP_Query( $args ); ?>
<?php if ( $wp_query->have_posts() ) : ?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?><li class=”x-post-carousel-item”>
<?php x_ethos_entry_cover( ‘post-carousel’ ); ?><?php endwhile; ?>
<?php endif; ?><?php wp_reset_query(); ?>
<script>
jQuery(document).ready(function() {
jQuery(‘.x-post-carousel’).slick({
autoplay: true,
autoplaySpeed: 2000,
speed : 500,
slide : ‘li’,
slidesToShow : <?php echo x_get_option( ‘x_ethos_post_carousel_display_count_extra_large’ ); ?>,
slidesToScroll : 1,
responsive : [
{ breakpoint : 1500, settings : { speed : 500, slide : ‘li’, slidesToShow : <?php echo x_get_option( ‘x_ethos_post_carousel_display_count_large’ ); ?> } },
{ breakpoint : 1200, settings : { speed : 500, slide : ‘li’, slidesToShow : <?php echo x_get_option( ‘x_ethos_post_carousel_display_count_medium’ ); ?> } },
{ breakpoint : 979, settings : { speed : 500, slide : ‘li’, slidesToShow : <?php echo x_get_option( ‘x_ethos_post_carousel_display_count_small’ ); ?> } },
{ breakpoint : 550, settings : { speed : 500, slide : ‘li’, slidesToShow : <?php echo x_get_option( ‘x_ethos_post_carousel_display_count_extra_small’ ); ?> } }
]
});
});</script>
<?php endif; ?>
October 20, 2016 at 8:47 pm #1224816
Rue NelModeratorHello There,
Sorry for the confusion. You can display featured post in the post carousel with a random order. Since you have your child theme active and ready, please follow the following steps below:
1] Using Notepad or TextEdit or Sublime Text or any text editor, please create a new file in your local machine.
2] Insert the following code into that new file<?php // ============================================================================= // VIEWS/ETHOS/_POST-CAROUSEL.PHP // ----------------------------------------------------------------------------- // Outputs the post carousel that appears at the top of the masthead. // ============================================================================= GLOBAL $post_carousel_entry_id; $post_carousel_entry_id = get_the_ID(); $is_enabled = x_get_option( 'x_ethos_post_carousel_enable' ) == '1'; $count = x_get_option( 'x_ethos_post_carousel_count' ); $display = x_get_option( 'x_ethos_post_carousel_display' ); switch ( $display ) { case 'most-commented' : $args = array( 'post_type' => 'post', 'posts_per_page' => $count, 'orderby' => 'comment_count', 'order' => 'DESC' ); break; case 'random' : $args = array( 'post_type' => 'post', 'posts_per_page' => $count, 'orderby' => 'rand' ); break; case 'featured' : $args = array( 'post_type' => 'post', 'posts_per_page' => $count, 'orderby' => 'rand', 'meta_key' => '_x_ethos_post_carousel_display', 'meta_value' => 'on' ); break; } ?> <?php if ( $is_enabled ) : ?> <ul class="x-post-carousel unstyled"> <?php $wp_query = new WP_Query( $args ); ?> <?php if ( $wp_query->have_posts() ) : ?> <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?> <li class="x-post-carousel-item"> <?php x_ethos_entry_cover( 'post-carousel' ); ?> </li> <?php endwhile; ?> <?php endif; ?> <?php wp_reset_query(); ?> <script> jQuery(document).ready(function() { jQuery('.x-post-carousel').slick({ speed : 500, slide : 'li', slidesToShow : <?php echo x_get_option( 'x_ethos_post_carousel_display_count_extra_large' ); ?>, slidesToScroll : 1, rtl : <?php echo json_encode( is_rtl() ); ?>, responsive : [ { breakpoint : 1500, settings : { speed : 500, slide : 'li', slidesToShow : <?php echo x_get_option( 'x_ethos_post_carousel_display_count_large' ); ?> } }, { breakpoint : 1200, settings : { speed : 500, slide : 'li', slidesToShow : <?php echo x_get_option( 'x_ethos_post_carousel_display_count_medium' ); ?> } }, { breakpoint : 979, settings : { speed : 500, slide : 'li', slidesToShow : <?php echo x_get_option( 'x_ethos_post_carousel_display_count_small' ); ?> } }, { breakpoint : 550, settings : { speed : 500, slide : 'li', slidesToShow : <?php echo x_get_option( 'x_ethos_post_carousel_display_count_extra_small' ); ?> } } ] }); }); </script> </ul> <?php endif; ?>3] Save the file named as
_post-carousel.php
4] Upload this file to your server in the child theme’s folder
wp-content/themes/x-child/framework/views/ethos/What has changed in the code? It is just the orderby line. It was changed from
datetorand;case 'featured' : $args = array( 'post_type' => 'post', 'posts_per_page' => $count, 'orderby' => 'rand', 'meta_key' => '_x_ethos_post_carousel_display', 'meta_value' => 'on' );Please let us know if this works out for you.
October 21, 2016 at 5:51 am #1225250
DariyaParticipantHi Rue Nel,
Yep, it worked woohooo!!! Thank you sooooo much!
You guys are really awesome! 🙂October 21, 2016 at 8:26 am #1225425
Paul RModeratorYou’re welcome! 🙂
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1223749 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
