• Resolved phaidonas

    (@phaidonas)


    Hello, im trying to make a custom image slider,i made a front page.php and try to generate some post feature image with a WP_Query.But the code only generates one, with the post title it works great.here is the code:

    <?php
    
    $args=array(
    	'posts_per_page'=>3
    );
    
    // The Query
    $the_query = new WP_Query( $args );
    
    // The Loop
    if ( $the_query->have_posts() ) {
    	echo '<ul>';
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
    
    		if ( has_post_thumbnail() ) {
    	the_post_thumbnail();
    }
    
    	}
    
    	/* Restore original Post Data */
    	wp_reset_postdata();
    } else {
    	// no posts found
    }
    
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • are you sure that all those three latest posts have a featured image?

    to get only posts with featured image, try this modification:

    $args=array(
    	'meta_key' => '_thumbnail_id',
    	'posts_per_page'=>3
    );
    Thread Starter phaidonas

    (@phaidonas)

    i find it,yes they didnt have,i fix it, do you know how in the array use the rand parameter to take random posts?

    try:

    $args=array(
    	'meta_key' => '_thumbnail_id',
    	'posts_per_page'=>3,
    	'orderby' => 'rand'
    );
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘The post Thumbnail’ is closed to new replies.