Last active
April 6, 2018 21:41
-
-
Save cornelisonc/500f166a85e138030a57d6d1dde8298b to your computer and use it in GitHub Desktop.
WordPress blog archive: featured image or dynamic random featured image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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