Tutorial on randomly displaying thumbnails when there are no illustrations on the DUX theme article content page of a WordPress site

888u

Last update at :2024-01-24,Edit by888u

DUX should be the most commonly used theme on host evaluation blog sites, such as Snail Blog, Lao Zuo Blog (Lao Zuo Notes), Lao Tribe, Host Reference, VPSGO, VEIDC.COM, foreign host evaluation, etc., including our blog This site is also implemented using the WordPress site DUX theme.

Today our blog will share with you the featured image of the article on the DUX theme homepage of the WordPress blog system site. If there are no illustrations in the article content or the first featured image is not enabled, a random image in the random directory will be automatically called as a thumbnail. , so that the thumbnail area is no longer a monotonous gray frame and inferior image display.

Effect:

Steps to randomly display thumbnails:

Find the functions-theme.php file in the dux theme directory. At about line 785 (the number of lines may change depending on the version), find the following code:

if( $r_src ){ if( _hui('thumbnail_src') ){ return sprintf('%s', $r_src, $post->post_title._get_delimiter().get_bloginfo(' name'), get_stylesheet_directory_uri().'/img/thumbnail.png'); }else{ return sprintf('%s', $r_src, $post->post_title._get_delimiter().get_bloginfo('name')); } }else{ return sprintf('', get_stylesheet_directory_uri().'/img/thumbnail.png'); } }

Replace with:

/*Featured picture of the home page article. If there is no picture in the article content, or the first picture is not enabled as the featured picture, any picture in the random directory will be used. */ if( $r_src ){ if( _hui('thumbnail_src') ){ return sprintf('%s', $r_src, $post->post_title._get_delimiter().get_bloginfo(' name'), get_stylesheet_directory_uri().'/img/thumbnail.png'); }else{ return sprintf('%s', $r_src, $post->post_title._get_delimiter().get_bloginfo('name')); } }else{ /*return sprintf('', get_stylesheet_directory_uri().'/img/thumbnail.png');*/ $random = mt_rand(1, 30);//Pictures of numbers 1-30 return sprintf('', get_stylesheet_directory_uri().'/img/random/'.$random.'.jpg'); } }

Download the random image file here:

randomdownload

Download the image, and then extract the image folder to the img folder in the theme directory, as shown in the picture:

Recommended site search: all-purpose virtual host, ip168, foreign server, website registration information query, which server protection is the best, Japanese server rental Japanese server, free external network server, application for free space and domain name, foreign server, space service provider ,

Tutorial on randomly displaying thumbnails when there are no illustrations on the DUX theme article content page of a WordPress site

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码