在此先感谢任何需要时间回复的人。我真的很感激这个网站!我有一个函数可以加载它在给定目录中找到的所有图像(见下文)。我试图解决的问题是图像以随机顺序加载。图像以随机顺序加载?
我希望图像能够通过基于文件名的字母顺序加载(widget-1.jpg例如会在widget-2.jpg之前加载)。
功能如下...
function get_images()
{
global $options;
foreach ($options as $value) {
if (get_settings($value['id']) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings($value['id']); }
}
if($my_custom_images !== "")
{
echo $my_custom_images;
}
else
{
$dir = 'wp-content/uploads/';
$url = get_bloginfo('url').'/wp-content/uploads/';
$imgs = array();
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if (!is_dir($file) && preg_match("/\.(bmp|jpeg|gif|png|jpg|)$/i", $file))
{
array_push($imgs, $file);
}
}
closedir($dh);
} else {
die('cannot open ' . $dir);
}
foreach ($imgs as $idx=>$img)
{
$class = ($idx == count($imgs) - 1 ? ' class="last"' : '');
echo '<img src="' . $url . $img . '" alt="' .$img . '"' . $class . ' />';
}
}
}
完美的作品Yacoby。谢谢您的帮助! –