WordPress blog archive: featured image or dynamic random featured image
<div class="list-article-thumb"> | |
<a href="<?php echo esc_url( get_permalink() ); ?>"> | |
<?php | |
if ( has_post_thumbnail( ) ) { | |
the_post_thumbnail(); | |
} else { | |
$images_iterator = new FilesystemIterator( | |
WP_CONTENT_DIR . '/themes/yourthemename/images/', | |
FilesystemIterator::SKIP_DOTS | |
); | |
$rand = rand(1, iterator_count($images_iterator)); | |
echo '<img alt="" src="'. get_stylesheet_directory_uri() . '/images/' . $rand . '.jpg' .'">'; | |
} | |
?> | |
</a> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment