2010-11-08 132 views
0

我试过了几个插件,但似乎无法使其工作。我在主主题的目录“http://www.ecgresources.com/WP/wordpress/wp-content/themes/theme335/images/random-images”中创建了一个新文件夹。我想要显示的div叫做main。我希望能够在每个页面上放置一些代码并从该目录中提取图像。如果任何人有任何提示或提示,我将不胜感激!在WordPress网站上的不同页面上显示不同的图像

这里是在style.css中的样式

。主要{宽度:766px; border:1px solid#818181;边框顶部:无;文本对齐:左;背景颜色:#030409;}

这主要风格被称为中的header.php

回答

1

试试这个。您可能需要调整图像通配符以适合您的需求。

<?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> 
相关问题