Hello, I am using the Ethos Stack and was wondering if there was a way to randomize the order of my blog posts displaying on my front page (not the carousel or post slider but the actual posts going down my page) Thanks!
Hi there,
Thanks for writing in.
Is it the standard lists or the one with filter? Randomization should be doable either by global query or custom query (for filtered posts). Let’s do this, if it’s standard lists then add this code to your child theme’s functions.php
function ethos_random_posts( $query ) {
if ( is_home() ) {
$query->set( 'orderby', 'rand' );
}
}
add_action( 'pre_get_posts', 'ethos_random_posts' );
Or do this if its the filtered one, copy this file from the main theme folder \framework\views\ethos\_index.php
to your child theme matching the same folder structure/path. Then edit _index.php
in your child theme and replace this line,
$wp_query = new WP_Query( array( 'post_type' => 'post', 'paged' => $paged, 'cat' => $category->term_id ) );
with this
$wp_query = new WP_Query( array( 'post_type' => 'post', 'paged' => $paged, 'cat' => $category->term_id, 'orderby' => 'rand' ) );
Hope this helps.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.