开发者

Displaying different images on different pages on a WordPress site

开发者 https://www.devze.com 2023-01-24 10:42 出处:网络
I\'ve tried a couple of plugins but can\'t seem to 开发者_Python百科get it to work.I\'ve created a new folder in the main theme\'s directory \"http://www.ecgresources.com/WP/wordpress/wp-content/theme

I've tried a couple of plugins but can't seem to 开发者_Python百科get it to work. I've created a new folder in the main theme's directory "http://www.ecgresources.com/WP/wordpress/wp-content/themes/theme335/images/random-images". The div I want to display is called main. I want to be able to put a little code on each page and pull an image from that directory. If anyone has any hints, or tips, I would appreciate it!

Here is the style in style.css

.main {width:766px; border:1px solid #818181; border-top:none; text-align:left; background-color:#030409;}

This main style is called in header.php


Try this. You may want to adjust the image wildcards to suit your needs.

<?php
$theme_dir = get_template_directory();
$img_dir = $theme_dir . '/images/random-images/';
$image_files = glob( $img_dir . "{*.jpg,*.JPG}", GLOB_BRACE );
shuffle( $image_files );
$file = str_replace( $theme_dir, '', $image_files[0] );
?>

<img src="<?php echo( get_bloginfo('template_url') . $file ); ?>" /></div>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号