首页 文章

在WordPress网站上的不同页面上显示不同的图像

提问于
浏览
0

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

这是style.css中的样式

.main {width:766px; border:1px solid#818181;边框顶部:无;文本对齐:左;背景色:#030409;}

这个主要样式在header.php中调用

1 回答

  • 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>
    

相关问题