On a field I have a thumbnail that when you click on it, opens an image gallery.
But now I also want to add a link that points to the same gallery.

Is there a way to do this by adding a php snippet in the .tpl.php file?
Or is there a way to accomplish this using Views?

Thanks!

Comments

mmncs’s picture

Subscribing

mmncs’s picture

Here is a solution for views:

Add a link to the header:

<a href="#" id="show-gallery">view gallery</a>

Make a JQuery function like this:

(function ($) {
  Drupal.behaviors.OpenColorbox = {
    attach: function(context, settings){
      $('#show-gallery', context).click(function () {
        $('.colorbox').colorbox({open:true});
      })      
    }
  }
}(jQuery));

If you want to a link for each item you can make a contextual filter on the image, add the file uri to the display and rewrite it for colorbox:

<a class="colorbox colorbox-inline" rel="gallery-all" href="[uri]">View gallery </a>

CreativeJS’s picture

Ok I'm a bit of a noob when it comes to colorbox and Drupal coding - what header do you add that first code line to? In the html of the page with the gallery or the page that you want to link the gallery from?

I would love to link THIS gallery from THIS page's photos and a direct link at the bottom.

Thanks in advance!!

-Jess

atiba’s picture

Jess, it's also possible to add markup text to a Views header.
Simply make a new 'View' and there you'll find the Header option in section Block/Page settings.
I think you need to add the line of code up there.

I will check it out myself, i'll let you know if it works.

- Cesar

lsolesen’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nodecode’s picture

Status: Closed (fixed) » Active

I'm changing the status here because the solution explanation is incomplete.

@mmncs: I fully understand where and how to implement the Views header code, however, can you please explain where and how the jQuery function is to be implemented?

Thank you for your time.

mmncs’s picture

Here is an explanation: http://drupal.org/node/171213

bellagio’s picture

Does your view has 'field Content: Image (field_image_cache)' and header <a href="#" id="show-gallery">view gallery</a> in the same view ?

When you click on 'view gallery', it adds js to open image in the colorbox.
but where is your gallery?

i set up my view with 'field Content: Image (field_image_cache)' exclude from display and add header.
Then i call the view in node template, but when i click on the text link, nothing happens.

<?php
$view = views_get_view('view-name');
print $view->execute_display('default');
?>

can you share screenshot of your view, or explain little bit further? thank you.

fraweg’s picture

Issue summary: View changes

Hello,

the is a solution on #2 witch works great! Thanks for that! But what changes have I to make in the jquery-code if the content have two imagefields an I want want to user only one for the colorbox?

Best regards
Frank

EDIT: Another question: Is it possible to let it work with an image field that is excluded from the display ?

Genocode’s picture

#2 solution definitely pointed me in the right direction. Also, if anyone is interested in additional functionality, you can view the source of Colorbox Example 5 and check out the jQuery examples.

My need went beyond starting the colorbox slideshow on the same view, I needed to start the colorbox slideshow that was on another view. However, I resorted to hyperlinks that pointed to the images and hid them (the links) within a div. Basically a replica of http://www.jacklmoore.com/colorbox/example5/

keerthithavas’s picture

Hi,
I have created a view link in custom text to display the colorbox gallery if the link is clicked .But i dont know how to pass the image field as url .please share your thoughts.
Thanks,
keerthi.

Neslee Canil Pinto’s picture

Status: Active » Closed (works as designed)