0

I am about to implement a img gallery in a node template. The gallery has the usual HTML markup (a span with bgimage, wrapped by a div...) I do not have any knowledge on php, but - in the last 24h - i was able to modify some code snippets i found:

    <?php
$node = node_load($nid);
$image = field_get_items('node', $node, 'field_project_image');
$image_url =file_create_url($node->field_project_image['und'][0]['uri']);
foreach ($image as $key=>$value) {
$output = field_view_value('node', $node, 'field_project_image', $image[$key], array(
  'type' => 'image',
  'settings' => array(
    'image_style' => 'thumbnail', //place your image style here

  ),
));

print '<div class="singleswipe">';
print '<span id="swipe_bg_image" role="img" style="background-image:url(\'' .$image_url. '\'); background-size:100%; background-position: 50% 50%; background-repeat:no-repeat">';


print '<span class="inner"></span>';

print '</span>';


print '<span class"title">title of the img???</span>';

print '</div>';


}
?>

This works somehow. BUT: it always shows the same picture. (Apparently it is always the same image_url), plus: I don't have any idea how to implement the "title" or "alt" text for every single image. Please, I am in a serious need for help now...

4
  • Do you have enable 'alt' and 'title' for image field in admin? Are you creating slideshow gallery or displaying multiple images only ? Sep 25, 2013 at 11:19
  • yes, i have enabled both of them. i am creating a slideshow gallery. actually, i think my problem is more a php-related one, but I am not sure b/c - as i already said - i am not very familiar with php.
    – julmoel
    Sep 25, 2013 at 11:38
  • You can use drupal.org/project/field_slideshow module to generate slideshow in node details page. Sep 25, 2013 at 11:54
  • thanks, i know this module. but I am forced to work with swipejs.com
    – julmoel
    Sep 25, 2013 at 12:10

1 Answer 1

0

You can follow the below code. Please change 'field_flexslider_example_image' with your field name in content type.

<?php
$node = node_load($nid);

$image = field_get_items('node', $node, 'field_flexslider_example_image');

foreach ($image as $key => $value) {
$output = field_view_value('node', $node, 'field_flexslider_example_image', $image[$key], array(
  'type' => 'image',
  'settings' => array(
    'image_style' => 'thumbnail', //place your image style here

  ),
));

$image_url = file_create_url($value['uri']);
$alt = $value['alt'];
$title = $value['title'];

print '<div class="singleswipe">';
print '<span id="swipe_bg_image" role="img" style="background-image:url(\'' .$image_url. '\'); background-size:100%; background-position: 50% 50%; background-repeat:no-repeat">';


print '<span class="inner"></span>';

print '</span>';


print '<span class"title">' . $title . '</span>';

print '</div>';


}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.