[英]what's the correct image src path to display the image in wordpress?
[英]What's the Drupal function to display image src?
我有一个HTML文件和一些图像。 主题化时,我使用了drupal_get_path
函数来显示图像,但是都没有显示。 我已经尝试过下面的代码。 如果有人可以帮助,那将是很大的帮助。
<?php echo drupal_get_path('theme', 'THEME_NAME'); ?>/images/slider/slide1_baner1.jpg" alt="" />
使用$ GLOBALS ['theme']获取当前主题的路径(可选)。
使用theme_image获取图像的html。
Drupal解决此问题的方法如下所示:
$variables = array(
'path' => drupal_get_path('theme', 'THEME_NAME').'/images/slider/slide1_baner1.jpg',
'alt' => 'Alt of image',
'title' => 'Image title',
'width' => '50%',
'height' => '50%',
'attributes' => array('class' => 'img-class', 'id' => 'banner1'),
);
$output = theme('image', $variables );
请尝试使用以下方式!
<?php global $theme; // Returns the current active theme name. ?> <img"<?php echo drupal_get_path('theme', $theme); ?>/images/slider/slide1_baner1.jpg" alt="" />
只需尝试调试一下drupal_get_path()
返回的内容。 可能适合您,它没有返回确切的可浏览路径,这就是为什么图像不出现的原因。
保持Drupalizing :)
我最近在Drupal Answers上问了一个类似的问题: https : //drupal.stackexchange.com/questions/121488/whats-the-correct-relative-path-to-a-local-image 。
您可以使用代码
<?php global $base_url; ?>
<img src="<?php echo $base_url; ?>/sites/all/themes/MY-THEME/images/slider/slide1_baner1.jpg">
或功能file_create_url
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.