我是drupal的初学者。我想从 drupal 的特定文件夹中获取图像。有没有办法直接从任何特定的自定义主题中获取 drupal 图像。
问问题
388 次
2 回答
0
您应该只使用主题中的图像。您可以像这样获得主题的路径:
$theme = drupal_get_path('theme',$GLOBALS['theme']);
将 ie 放在使用主题图像的模板文件的顶部。然后在您的主题模板中,您可以拥有以下内容:
<img src="/<?php echo $theme; ?>/images/my_image.png">
如果您将主题图像存储在images
目录中...
于 2015-10-08T08:19:55.143 回答
0
如果本地文件系统上的图像路径数组是您想要的 - 使用此代码,它应该可以满足您的需求。获取sites/default/files/vegas
目录中的所有 png jpg gif 路径。
//We will use the stream wrapper to access your files directory
if ($wrapper = file_stream_wrapper_get_instance_by_uri('public://')) {
//Now we can easily get an actual path to that folder
$directory = $wrapper->realpath();
//Don't forget to append your "vegas" subfolder here
$directory .= DIRECTORY_SEPARATOR . 'vegas' . DIRECTORY_SEPARATOR;
$images = glob($directory . "*.{jpg,png,gif}", GLOB_BRACE);
foreach($images as $imagePath)
{
//Do your thing!
echo $imagePath;
}
}
于 2015-10-08T22:20:32.783 回答