Random Order on Front Page

Mauer Themes Support Essentialist Random Order on Front Page

This topic contains 3 replies, has 2 voices, and was last updated by  Paul 8 months, 4 weeks ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2869

    vvivianne
    Participant

    Hi there!

    I was trying to modify the template for 2 col Layout so the post order is random.
    But it won´t work.
    Can you please tell me, what I need to know, so I can use the standard wordpress array things to sort it?

    #2890

    Paul
    Keymaster

    Hello,

    You can randomize the order of posts on your blog home page each time the page is loaded by using the pre_get_posts filter. To do that please do the following:

    In your Admin Panel go to ‘Appearance’ -> ‘Editor’, find the functions.php file.

    Go to the end of the file, just above the closing ?> tag insert the following code:

    function randomize_posts_output( $query ) {
    	if ( is_home() ) {
    		$query->set( 'orderby', 'rand' );
    	}
    }
    add_action( 'pre_get_posts', 'randomize_posts_output' );

    The result should look like this: please see screenshot.

    Click the ‘Update file’ button.

    Regards,
    Paul

    ——
    A little disclaimer: It’s best to do such customizations in a child theme or a custom plugin, so they do not get overwritten during theme updates. However, of course, you can always re-introduce them after a theme update.

    #2907

    vvivianne
    Participant

    Thank you!
    I put this in my childtheme´s functions.php file and it works perfectly!
    Maybe you could think about adding this to the theme settings as an option. 😉

    #2908

    Paul
    Keymaster

    You are very welcome! I’ll consider adding this as an option.

    If you enjoy the theme (or the support), I’d be very grateful if you could rate it on ThemeForest. This literally takes a moment, however, makes a big difference. Thank you.

    Regards,
    Paul

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.