调整图像属性,以便我可以更改src

时间:2013-05-21 02:22:26

标签: php image drupal drupal-7

<img class="lazy" title="Windows 8" alt="Windows 8" src="http://b.a.org/sites/default/files/styles/thumbnail/public/category_pictures/Windows%20Media%20Player%20alt.png?itok=NXy-3w5_" href="lazy" data-original="http://b.a.org/sites/default/files/styles/thumbnail/public/category_pictures/Windows%20Media%20Player%20alt.png?itok=NXy-3w5_">

我想调整src,以便它可以显示“/sites/all/themes/s5/images/blank.jpg”而不是图片网址。你可以帮我修改下面我在Drupal 7的template.php中使用的代码来实现这个目的吗?

function s5_preprocess_image(&$variables) {
 if ($variables['style_name'] == 'thumbnail') {
     $variables['attributes']['class'][] = 'lazy';
     $variables['attributes']['data-original'][] = file_create_url($variables['path']);
}}

非常感谢!!

1 个答案:

答案 0 :(得分:1)

在“if”块的底部添加了一行:

function s5_preprocess_image(&$variables) {
   if ($variables['style_name'] == 'thumbnail') {
       $variables['attributes']['class'][] = 'lazy';
       $variables['attributes']['data-original'][] = file_create_url($variables['path']);
       $variables['path'] = '/sites/all/themes/s5/images/blank.jpg';
   }
}