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>
精彩评论