Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
You want a link that leads to a Colorbox gallery using images uploaded with Imagepicker.
Here is how.
This assumes you have Imagepicker and Colorbox installed.
First of all create a group in Imagepicker, we'll call it 'gallery1'.
Upload some images with Imagepicker, adding them to the group.
You will need full php rights to do the following.
Create a page or a block containing this code:
// visible image. edit this to suit, this is what you click on to activate the gallery. Does not have to be an image.
$fimg = "<img title='Photo Gallery' alt='A photo gallery' src='/sites/all/files/imagepicker/1/image-to-click-on.jpg'>";
// name of group
$gal = "gallery1";
$fpath = DIRECTORY_SEPARATOR . file_directory_path() . DIRECTORY_SEPARATOR . IMAGEPICKER_FILES_DIR . DIRECTORY_SEPARATOR;
$sql = "SELECT DISTINCT i.img_id, i.uid, i.img_name, i.img_title, img_description
FROM {imagepicker} AS i JOIN {users} AS n USING (uid),
{imagepicker_user_groups} AS u JOIN {imagepicker_group_images} AS g USING (gid)
WHERE g.img_id=i.img_id AND u.group_name = '$gal'";
$result = db_query($sql);
$ct = 0;
$out = "";
while ($row = db_fetch_array($result)) {
$n = $row['img_name'];
$t = $row['img_title'];
$d = $row['img_description'];
$full = $fpath . $row['uid'] . DIRECTORY_SEPARATOR . $n;
$thumb = $fpath . $row['uid'] . DIRECTORY_SEPARATOR . IMAGEPICKER_THUMBS_DIR . DIRECTORY_SEPARATOR . $n;
$out .= "<a href='$full' class='colorbox' rel='$gal' title='$d'>";
if (! $ct) {
$out .= $fimg;
}
else {
$out .= "<img src='$thumb' alt='$t'>";
}
$out .= "</a>";
if (! $ct) {
$out .= "<div style='display:none'>";
}
$ct++;
}
$out .= "</div>";
echo $out;
To change the gallery just add/remove images from the group.
The code can of course be written more compactly but this shows how it works.
Hope it helps someone.
Comments
Comment #1
hutch CreditAttribution: hutch commentedHere is the same sort of thing but for Drupal 7:
Comment #2
hutch CreditAttribution: hutch commentedThis functionality is now builtin and will be available in the dev versions tomorrow.
Comment #3
hutch CreditAttribution: hutch commentedComment #4
JGO CreditAttribution: JGO commentedHow to use this?
All my images show one by one and never with a previous/next button. Any help on how to do this with imagepicker would be appreciated ! :)
Comment #5
hutch CreditAttribution: hutch commentedUse the latest stable or dev version of Imagepicker.
Create a group in imagepicker and add the images you want in the gallery to the group.
Go into admin imagepicker general settings and enable gallery blocks, save and tell it how many blocks you want. You will need colorbox set up too of course.
Go to the blocks admin and configure the block to use the group you want, where you want the block, what to click on etc
Done.
Comment #6
JGO CreditAttribution: JGO commentedThx a lot hutch, but if I understand correctly this will only work for blocks?
I don't understand why not my images on the node with a link to colorbox have this behaviour. I think this really is a missing feature if this is not possible :(
Comment #7
hutch CreditAttribution: hutch commentedTo get images to be recognised as a gallery by colorbox give them a 'rel' attribute, eg add rel='gallery1' so you have something like
In the first one and something like
In all the other images.
See the colorbox documentation for more details
Comment #8
JGO CreditAttribution: JGO commentedHi, This works indeed, I just added rel="gallery1" to all my links to pictures. It would be good if you could support this when inserting the image. E.g. if you select "colorbox", there should also be a button for enabling all pictures on the node in a galery. That would be very handy and would avoid fiddling with html code ;)
Comment #9
hutch CreditAttribution: hutch commentedI will look into the possibility. Please remember that imagepicker does not and cannot know what has been inserted before, it only knows about what is being inserted now.
Comment #10
JGO CreditAttribution: JGO commentedThanks! You could just use an option like the insert module has:
http://www.coagula.org/content/sites/default/files/images/colorbox.jpg
There you have a global option. If you just always add the tag "All-Gallery" or something alike when a global option is set, then all images will show up in the same gallery.
Comment #11
hutch CreditAttribution: hutch commentedWhere does the insert module get its list of images from?
Comment #12
JGO CreditAttribution: JGO commentedFrom the attached images. But that is not very important. It just adds the same tag on insert of every image.
Comment #13
hutch CreditAttribution: hutch commentedThe option to add a 'rel' attribute is available in dev for D6 and D7, along with Imagecache support.