• How to make random post image on refresh page and display 4 image in vertical?

    Example: Mazushi.net

Viewing 1 replies (of 1 total)
  • You would use a WP_Query to call only the Featured Image of all the posts and in the wp_query $args, the “orderby” would be ‘rand’ (random order), similar to this:

    <?php
    $args = array(
    	'posts_per_page' => 4,
    	'orderby' => 'rand'
    );
    ?>
    
    <?php $the_query = new WP_Query( $args ); ?>
    <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
    	<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		<?php if ( has_post_thumbnail() ) {
    			the_post_thumbnail();
    		} ?>
    	</div>
    
    <?php endwhile;
    wp_reset_query();
    endif; ?>
Viewing 1 replies (of 1 total)

The topic ‘How to make random on load page.’ is closed to new replies.