This code enables you to display a random featured image on any archive page type, if non is added. On top of this, it doesn’t display any duplicates so all images will be unique.
There’s at least 2 ways to do this, both of which are included in this premium tutorial for members.
Firstly, lets check the demo video.
In this demo, we’ve added 6 unique images to a folder named random in the child themes root directory. We’re added the code directly to the archive-portfolio.php template file which displays 6 posts per page. The code makes sure a unique image is displayed for each entry on each archive page if no featured image is added, otherwise it displays the featured image.
Tested using the Minimum Pro child theme by StudioPress in the archive-portfolio.php template file.
Note : If you want to use a unique random image for each paginated archive page, you will need to add the same number of images to match your posts per page settings. Example : If you are showing 20 posts per page, you’ll need to add 20 unique images named 1.png to 20.png in the random images folder.
Here’s the code for logged in members