Invoke a colorbox when a person presses a link on a view PHP field

Public

This snippet create a colorbox slideshow - ready to be inserted into a Views PHP field. The colorbox slides over the images pointed by the hidden links outputted by the PHP script. It assumes the colorbox module is installed and enabled, so that the colorbox jQuery is already on page.

</> CopyGet raw version
php
  1. <?php if($data->nid) : ?>
  2. <script>
  3. (function($) {
  4. $(document).ready(function(){
  5. $(".cbox<?=$data->nid ?>").colorbox({rel:'.cbox<?=$data->nid ?>', width: "80%", height: "80%", slideshow:true});
  6. });
  7. })(jQuery);
  8. </script>
  9. <div>
  10. <?php
  11. if (count($data->field_field_pictures) >0) :
  12. for ($i=0; $i < count($data->field_field_pictures); $i++) {
  13. $url = file_create_url($data->field_field_pictures[$i]['raw']['uri']);
  14. $t = $data->field_field_pictures['raw']['title'];
  15. $style = '';
  16. if ($i > 0) $style='display:none';
  17. echo "<a class='cbox".$data->nid."' href='$url' title='$t' style='$style'>";
  18. if ($i == 0) echo "<img src='../sites/all/themes/mytheme/images/btn_show.png' width='15' height='15'>";
  19. echo "</a>";
  20. }
  21. endif;
  22. ?>
  23. <?php endif; ?>
  24. </div>