0

I need a slideshow and sometime the images need to have a link. This link might be external or internal and it is posted by users. I use rewrite results in my view. However, sometimes the picture does not have a link. So this does not work for me.

I am using Drupal 7, Views, link and slideshow, picture module. My content type has the following fields:

  • field_slideshow_image
  • field_link_in_picture
  • text_slideshow

I try used another modules but I need to use the picture module to make my pictures responsiveness. Other modules require that use the Formatter in views and picture module uses its own format.

1

I solved using theming in the view. I use the template in the image field. I ended up with a template like views-view-field--field-slideshow-image.tpl.php.

  <?php 
//dpm($row); only work if devel module enabled

$url='';

if (!empty($row->field_field_link_in_picture_)){

    $url=($row->field_field_link_in_picture_[0]['raw']['url']); 

}

if (!empty($url)) { 
     echo "<a href='$url'>" .$output ."</a>"; //print image with link    
}
else {
    print $output; //print image
}

?>

If someone knows a better way to do this please feel post it here. If I am not doing something in the Drupal way please let me know or you have another way to accomplish this. I would love to hear it :)

If you know little about theming views you can check this video to understand better Theming Views

-1

I would also use

//dpm($row); only work if devel module enabled
$url='';
if (!empty($row->field_field_link_in_picture_)){
  $url=($row->field_field_link_in_picture_[0]['raw']['url']); 
}
if (!empty($url)) { 
  echo "<a href='$url'>" .$output ."</a>"; //print image with link    
}
else {
  print $output; //print image
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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