[РЕШЕНО] Image style + colorbox программно

Главные вкладки

Аватар пользователя tommarkov tommarkov 22 сентября 2014 в 10:09

Добрый день! Прошу мне помочь, добрые люди!!!

В шаблоне вывожу img, и мне необходимо им приписать image style + class - colorbox + rel...
Данная конструкция нужна только лишь на одной странице и всего на 9 фото.

Пытаюсь объеденить эти конструкции, но ничего не выходит:

<?php
print theme('image', array(
    
'path' => drupal_get_path('theme''themename') . '/img/demo.png',
    
'alt' => 'my alt content',
    
'attributes' => array(
        
'id' => 'myId',
        
'class' => 'myClass',
    ))
);
?>
<?php
echo theme('image_style', array(
  
'style_name' => 'thumbnail',
  
'path'       => 'public://logo.jpg',
  
'alt'        => 'Image alt',
  
'title'      => 'Image title',
));
?>

Заранее спасибо всем откликнувшимся!

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Вот что вышло, рабочее:

<?php
$image 
theme(
  
'image_style',
  array(
    
'path' => 'public://img.jpg',
    
'style_name' => 'style',
    
'alt' => 'Alternate Text',
    
'title' => 'Title Text',
    
'attributes' => array(
        
'class' => array('colorbox'), 
        
'rel' => 'colorbox-ph'
    
)
  )
);
print 
$image;
?>

Итоговый код:

<?php
$image 
theme(
  
'image_style',
  array(
    
'path' => 'public://img.jpg',
    
'style_name' => 'style',
  )
);
print 
'<a class="colorbox" href="http://site.ru/img.jpg" rel="galery-colorbox" title="Title">';
print 
$image;
print 
'</a>';
?>

Комментарии

Аватар пользователя cosolom cosolom 30 сентября 2016 в 22:38

Правильнее было бы вот так:

  $image = theme('colorbox_imagefield', array(
    'image' => array(
      'style_name' => 'thumbnail', // image style for showing image on page
      'alt' => 'Alt',
      'title' => 'Title',
      'path' => $image_uri,
    ),
    'path' => file_create_url($image_uri),
    'gid' => 'grouping-gallery',
    'title' => 'Title in colorbox',
  )),
  print $image;

И если это вызывается на админских страницах, то надо еще вручную выполнить
  _colorbox_doheader();
Иначе colorbox не подцепит свои файлы на страницу.