Hi Guys,

I was trying to change the default layout of how the image.module displays IMAGE GALLERY pages with Drupal version 4.6.x and was tempted to hack the image.module but decided to setup a template override instead.

The image.module is a superb module and the default layout is fine..I just wanted to put some extra appropriate (and dynamic) content above the thumbnails, but, I knew that once I had hacked the image.module I would be making life much more difficult at a later stage when trying to upgrade or tweak that ammendment even more.

In essence the override gives you control at the $content level which is a step up from just having a node-image.tpl.php file in your theme folder.

I have posted the simple step-by-step approach in the handbook page called EXAMPLE - THEMING THE IMAGE GALLERY PAGES which is simple enough for non-php programmers to follow (carefully).

Instead of cluttering up the handbook page..I thought I would post a forum topic related to the book page so people can paste or post additional snippets/tricks etc. here instead.

I hope that's of use to others..

Dub

Comments

Dublin Drupaller’s picture

There's a bug that won't allow me to post this code in the handbook...here's the default image_gallery.tpl.php file

<?php
  // We'll add height to keep thumbnails lined up.
  $size = _image_get_dimensions('thumbnail');
  $width = $size['width'];
  $height = $size['height'];

  $content = '';
  if (count($galleries)) {
    $content.= '<ul class="galleries">';
    foreach ($galleries as $gallery) {
      $content .= '<li>';
      if ($gallery->count)
        $content.= l(image_display($gallery->latest, 'thumbnail'), 'image/tid/'.$gallery->tid, array(), NULL, NULL, FALSE, TRUE);
      $content.= "<h3>".l($gallery->name, 'image/tid/'.$gallery->tid) . "</h3>\n";
      $content.= '<div class="description">'. check_output($gallery->description) ."</div>\n";
      $content.= '<p class="count">' . format_plural($gallery->count, 'There is %count image in this gallery', 'There are %count images in this gallery') . "</p>\n";
      if ($gallery->latest->changed) {
        $content.= '<p class="last">'. t('Last updated: %date', array('%date' => format_date($gallery->latest->changed))) . "</p>\n";
      }
      $content.= "</li>\n";
    }
    $content.= "</ul>\n";
  }

  if (count($images)) {
    $height += 5;
    $content = 'this is the list of gallries<br><br>';
    $content.= '<ul class="images">';
    foreach ($images as $image) {
      $content .= '<li';
      if ($image->sticky) {
        $content .= ' class="sticky"';
      }
      $content .= ' style="height : '.$height .'px; width : '.$width.'px;"';
      $content .= ">\n";
      $content .= l(image_display($image, 'thumbnail'), 'node/'.$image->nid, array(), NULL, NULL, FALSE, TRUE);
      if (variable_get('image_teasers',0)){$content .= '<h3>'.l($image->title, 'node/'.$image->nid)."</h3>";}
      if (theme_get_setting('toggle_node_info_' . $image->type)) {
        $content .= '<div class="author">'. t('Posted by: %name', array('%name' => format_name($image))) . "</div>\n";
        $content .= '<div class="date">'.format_date($image->created)."</div>\n";
      }
      $content .= "</li>\n";
    }
    $content.= "</ul>\n";
  }

  if ($pager = theme('pager', NULL, variable_get('image_images_per_page', 6), 0)) {
    $content.= $pager;
  }

  If (count($images) + count($galleries) == 0) {
      $content.= '<p class="count">' . format_plural(0, 'There is %count image in this gallery', 'There are %count images in this gallery') . "</p>\n";
  }

  print $content;
 ?>

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

scroogie’s picture

Just a short remark: For Drupal 4.7 you have to use check_markup() instead of check_output().

vascopj’s picture

Did anyone get this to work in 4.7?

I tried but even if I changed the code it didn't seem to pick up the new image_gallery.tpl.php file.

thanks
S

wtdtan’s picture

thanks for the tip scroogie. that made my image_gallery.tpl.php page work when i changed that function name.
and it didn't take me long to find the answer to my problem!

lenart’s picture

Also you should use theme_username($image) instead of format_name($image) on line 38.

aboros@drupal.org’s picture

hi,

i use drupal 4.6 and i am trying to customize my gallery [image_module] with your hints from the handbook.
it works almost perfect. 'just' i recieve the following error:

Cannot modify header information - headers already sent by (output started at /usr/home/keret/public_html/themes/leaf/template.php:13) in /usr/home/keret/public_html/includes/common.inc on line 192.

if i post new image, or edit, or delete some old ones. :(
what is wrong? where should i begin to search for the problem? i'm not a programmer, but a bit familiar with php...

:b

Dublin Drupaller’s picture

That error is usually thrown up when there are extra spaces or lines at the end of a php file..i.e. after the ?> bit.

  1. Open your template.php or image_gallery.tpl.php file in a text editor
  2. Scroll to the bottom and delete any spaces or extra lines after the ?> at the end of the php
  3. Alternatively, just delete ?> from the last line in the file. I notice on other threads that it's not needed

Hope that helps.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

falcon9xr’s picture

Don't forget to move over the contents of the image.css file to the CSS file of whatever theme you're using if you want the images to show up without the list marks and in rows instead of one huge column.

Also, if anyone is using the box_grey theme and is having trouble with getting images to take up the full length of the screen, try changing

#sidebar-right {
        border-left: 1px dotted #fff;
        background: #fff
}

to

#sidebar-right {
        float : right;
        border-left: 1px dotted #fff;
        background: #fff
}
inthahousejamin’s picture

Ben W.

parisp’s picture

Thanks for the tips, this helped me wonderfully customize my gallery a bit.

However, what i would like to add is a

buttons on the bottom of an image preview so users can use those buttons to browse throught the pictures of that specific gallery. Any help or pointers on how to go about doing this will be much apreciated thanks
falcon9xr’s picture

I'm not really sure, but I'd suspect it would be somewhere in the image_display() function.

parisp’s picture

image_display() function handles the display of images in the gallery listing page, the gallery thumbnail images and the display of the image preview. basicle it handles any display of the image it self and not the layout where it apears.

after experementing a bit with the image.module code the function which handles the full view of an image when you click on it, which is the view i want to fiddle with and add previous,next image and back to gallery is the function image_view()

However i donno how about to change the gode to add that functionality or how to enable phptemplate to point to an image.tpl.php file to determine the layout without modifying the image.module code.

any help or pointers will be much aprecited

Ken Collins’s picture

I am trying to add a condition in the theme based on an $image's width. In this way I can wrap it with a span tag that constrain it to the right aspect ration and hence allows me to move an absolute positoined DIV based on this with CSS. What function() and code would I use to get this done? For instance, one of these?

    if ($attr['width'] == '68') {
      $content .= '<span class="img-vert">';
      $content .= l(image_display($image, 'thumbnail'), 'node/'.$image->nid, array(), NULL, NULL, FALSE, TRUE);
      $content .= '</span>';
    }
    if ($info['width'] == '90') {
      $content .= '<span class="img-horiz">';
      $content .= l(image_display($image, 'thumbnail'), 'node/'.$image->nid, array(), NULL, NULL, FALSE, TRUE);
      $content .= '</span>';
    }

I'm wondering too if I should invoke image_get_info() in drupal's image core or go to the image.module functions like image_display() which uses the durpal core or maybe or _image_get_sizes()

Dublin Drupaller’s picture

Hi Ken,

Try this...

<?php
list($width, $height, $type, $attr) = getimagesize($image);?>
<?php $themewidth = ($width +100); /*adding 100 pixels to the width of the image */ ;?>

then use the $themewidth value to set the width of a DIV or whatever.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

Ken Collins’s picture

I did not know where to put this. I tried placing it in the if (count($images)) part and uder the foreach statement of my image_gallery.tpl.php file, but id did not work. I could ever get any more than 100 for the $themewidth. If I put that $themewidth = ($width +100); at the top of my template file under the $size, $widht, $height variables, then $themewidth comes back of course to 190. Those variables at the top always return my image.module preferences and not the pixels dimensions of the image itself. Here is the structure of my (count ($images)) section now.

if (count($images)) {
  $content.= "\n".'<div id="galleries">'."\n";
  $content.= "\t".'<ul class="images">'."\n";
  foreach ($images as $image) {
    $content .= "\t"."\t"."<li";
    if ($image->sticky) {
      $content .= ' class="sticky"';
    }
    $content .= ">\n";
    $content .= '<h3>'.l($image->title, 'node/'.$image->nid)."</h3>";
    if { // Condition 1 
      $content .= '<span class="img-horiz">';
      $content .= l(image_display($image, 'thumbnail'), 'node/'.$image->nid, array(), NULL, NULL, FALSE, TRUE);
      $content .= '<span class="img-horiz">';
    }
    if {// Condition 2 
      $content .= '<span class="img-vert">';
      $content .= l(image_display($image, 'thumbnail'), 'node/'.$image->nid, array(), NULL, NULL, FALSE, TRUE);
      $content .= '<span class="img-vert">';
    }
    if (theme_get_setting('toggle_node_info_' . $image->type)) {
      $content .= '<div class="date">'.format_date($image->created, 'small')."</div>\n";
    }
    $content .= "</li>\n";
  }
  $content.= "</ul>\n";
  $content.= "</div>\n";
}
Dublin Drupaller’s picture

sorry ken..thought you wanted the snippet for a node-image.tpl.php file.

I'll look into it...it might be the variable_get($thumbsize) variable that is needed for the gallery pages.

Am busy right now but will look into it later

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

Ken Collins’s picture

I was able to find out the width of the image being used on the galleries page by setting these two vars.

$var1 = image_get_info(file_create_path($gallery->latest->images['thumbnail']));
$var2 = $var1[width];

Likewise, I was able to get the width of the thumbnail images used on the images page using these two vars.

$var1 = image_get_info(file_create_path($image->images['thumbnail']));
$var2 = $var1[width];
dhcreative’s picture

I have the module working in 4.7, and even modified it to display full-size (250x250px) images:
http://www.wtp-corp.com/?q=image/tid/18

It's imperative that these gallery pages display the gallery description at the top, and I've been trying to find a way to use the image_gallery.tpl.php file to do this. I tried copying this line to the image section:

$content.= '

'. check_markup($gallery->description) ."

\n";

No luck, though I did figure out how to modify this tag to display the image text body :)

Anyway, can anyone suggest a way to display the gallery description with the image gallery?

Thanks.

Deciphered’s picture

Hi dhassan,

I've been trying to figure this out as well, and I have figured it out.

Locate the following lines:

  if (count($images)) {
    $height += 5;

and add the following lines after it:

    foreach ($images[0]->taxonomy as $taxonomy) {
      $content.= '<div class="description">'. check_markup($taxonomy->description) ."</div>\n";
    }

Hope this helps.

lunk rat’s picture

Hello, I'm trying to get descriptions to appear above the thumbnails. I have image_gallery.tpl.php in place and working, but I cannot seem to get anything to display using your code or any other code from image_gallery.module. I'm on 5.7 and image_gallery.module v 1.5.2.14.

I know it is just a matter of the correct php snippet in the correct place in image_gallery.tpl.php

THANKS!

michellex’s picture

Do you guys know if there's a way to add some text to the thumbnails?

Also... my next page stuff doesn't work... http://www.steelveils.com/?q=image

underpressure’s picture

I am trying to text below thumbnails as they are in the default layout, has anyone firgured out how to do this?
--------------------->
underpressure
http://ravalonline.com

harrisben’s picture

That file is found in /modules/image/contrib/image_gallery

If you open that file in a text editor and find the section that says 'Theme a gallery', that's it. Everything there determines how the gallery looks (along with image_gallery.css).

If you do manage to get this working I'd love to hear how you did it, because I've had no success.

michellex’s picture

Some questions: In order to get a description in with the thumbnails, I had to hardcode it in, but I forgot that it would need to be different for different "albums". Is there a way to write an if statement or something so it will change?
(the description with the prints all can be the same, but not with collections, see link)

Also, the next and previous links don't work. Any ideas how to fix this?

And lastly... is there a way to limit how many images are shown on the page? I tried adjusting 'image_images_per_page', 6 (the 6 there) but that didn't do anything.

Here's the reference: http://www.steelveils.com/?q=image
(warning: artistic nudity)

If I get all this working, I'm seriously considering writing a tutorial. :)

thanks,
~M

www.steelveils.com

michellex’s picture

I figured out the next & previous issue. Apparently there is a patch that needs to happen for people on 4.6.4 - http://drupal.org/node/39566
.... Had no idea...

On to the next thing.
~

www.steelveils.com

hip’s picture

It's a nice pagination at the bottom of the pict galleries (at http://www.steelveils.com/?q=image). That's set at template.php, I guess. How do you achieve it? Is there any tutorial I've missed about paginating results?

In fact, I'm making use of Acid for the image galleries. Everything but the pagination/navigation system between big-sized pictures runs smoothly. Pagination has a 'First-previous-next-Last' scheme but is not working. It's showing some weird links. So I'd like to do/redo the pagination system to format it my way and to get to understand it, in order to be able to find wether the problem relies on Acid or template.php.

Thanx for any help.
hip

hip’s picture

Myself,

Don't worry about my above post. The pagination problem in Acidfree galleries was due to my client's horrible host (Arsys) misconfiguration. They're still on mySQL 3. I've applied the right patch (at http://drupal.org/node/41025) and everything is up and running.

Besides I don't have the time nor the strength to do no bettering on this job.

Thanx anyway,
hip

yvelle’s picture

Normally, I would just add a function as such:

function themename_image_gallery($galleries, $images) {

and this would override the theme call in the module. This is how I would do it to override theme_node and theme_block. But it isn't working for the image module. Is there something different about theming modules?

yvelle’s picture

That is exactly how it works. I simply forgot to upload the changes to my server :-p

jeforma’s picture

Has anybody got a working version of this for Drupal 4.7?

Visit GameBGS.com for all your gaming needs.

jfriesen’s picture

I, too, would love to see some help for 4.7

"Reality is what trips you up when you walk around with your eyes closed." F. Paul Wilson

yvelle’s picture

I'm using 4.7 and didn't have a problem overriding the theme as i suggested above.

gmak’s picture

I've got the gallery 'list' page (what appears when you click on a link like "mysite.com/image") theming according the code provided. However, when I click on a link to a specific gallery I get a blank page. There is no error generated in either the Drupal logs or the server logs. Just a big white blank page in the browser.

Has anyone managed to theme the image.module in 4.7? If so, I would really appreciate a walk-thru of your process.

maybourne’s picture

If you have an undefined function error or all your thumbnails are in one column..

In template.php:

/**
* Catch the theme_image_gallery function, redirect through the template api
* and point Drupal to your image_gallery.tpl.php file to determine the layout
* of your image gallery pages.
*/
function phptemplate_image_gallery($galleries, $images) {
  // Pass to phptemplate, including translating the parameters to an associative array. The element names are the names that the variables
  // will be assigned within your template.
  /* potential need for other code to extract field info */
   drupal_set_html_head(theme('stylesheet_import', base_path() . drupal_get_path('module', 'image_gallery') .'/image_gallery.css'));
return _phptemplate_callback('image_gallery', array('galleries' => $galleries, 'images' => $images));
  }

In image_gallery.tpl.php:

  // We'll add height to keep thumbnails lined up.
  $size = _image_get_dimensions('thumbnail');
  $width = $size['width'];
  $height = $size['height'];

  $content = '';
  if (count($galleries)) {
    $content.= '<ul class="galleries">';
    foreach ($galleries as $gallery) {
      $content .= '<li style="height : '.$height .'px">';
      if ($gallery->count)
        $content.= l(image_display($gallery->latest, 'thumbnail'), 'image/tid/'.$gallery->tid, array(), NULL, NULL, FALSE, TRUE);
      $content.= "<h3>".l($gallery->name, 'image/tid/'.$gallery->tid) . "</h3>\n";
      $content.= '<div class="description">'. check_markup($gallery->description) ."</div>\n";
      $content.= '<p class="count">' . format_plural($gallery->count, 'There is 1 image in this gallery', 'There are %count images in this gallery') . "</p>\n";
      if ($gallery->latest->changed) {
        $content.= '<p class="last">'. t('Last updated: %date', array('%date' => format_date($gallery->latest->changed))) . "</p>\n";
      }
      $content.= "</li>\n";
    }
    $content.= "</ul>\n";
  }

  if (count($images)) {
    $height += 75;
    $content.= '<ul class="images">';
    foreach ($images as $image) {
      $content .= '<li';
      if ($image->sticky) {
        $content .= ' class="sticky"';
      }
      $content .= ' style="height : '.$height .'px; width : '.$width.'px;"';
      $content .= ">\n";
      $content .= l(image_display($image, 'thumbnail'), 'node/'.$image->nid, array(), NULL, NULL, FALSE, TRUE);
      $content .= '<h3>'.l($image->title, 'node/'.$image->nid)."</h3>";
      if (theme_get_setting('toggle_node_info_' . $image->type)) {
        $content .= '<div class="author">'. t('Posted by: %name', array('%name' => theme('username', $image))) . "</div>\n";
        if ($image->created > 0) {
          $content .= '<div class="date">'.format_date($image->created)."</div>\n";
        }
      }
      $content .= "</li>\n";
    }
    $content.= "</ul>\n";
  }

  if ($pager = theme('pager', NULL, variable_get('image_images_per_page', 6), 0)) {
    $content.= $pager;
  }

  If (count($images) + count($galleries) == 0) {
      $content.= '<p class="count">' . format_plural(0, 'There is 1 image in this gallery', 'There are %count images in this gallery') . "</p>\n";
  }

  print $content;

mirko’s picture

Thanks!!!! Works fine now. Maybe this code should be added in the handbook?

okellhammer’s picture

I'm not a PHP coder and am a total Drupal newbie, (more used to operating in plone)

I want to turn *off* the authoring information that is being displayed in the image gallery of my drupal 4.7 site. I've tried uploading the above PHP scripts to my themes/bluemarine directory and it simply breaks the gallery, i.e. images won't display.

I get this error message:

"PHPTemplate was instructed to override the image_gallery theme function, but no valid template file was found."

The problem seems to be in the template.php file. When I remove it from the directory, the gallery loads fine, except (sigh) with that pesky authoring information under every image.

Can anyone help me?

Minty’s picture

This may be too simple for what you are doing, but you can normally remove authoring information without code amendment by going into:

>administer>themes>configure.
Select default to apply your settings to all themes, or select a particular theme.
There are selection buttons for show/hide authoring information for each content type.

Drupal developers have already done the work!

stoltoguzzi’s picture

Opening the gallery using something like image/29 where 29 is the id of the main gallery
will produce some kind of teaser list.

what I would like to have is a list in the form:

Gallery1
image1 image2 image3

Gallery2
image1 image 2

Gallery3
...

can somebody help for the first steps

kvarnelis’s picture

some images are too big for my theme. i'd like them to pop up as separate windows. any idea how to code that? i am using 4.7.

sepeck’s picture

Look at the lightbox2 module as a starting point..

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

barrygirsh’s picture

I am trying to change an image's Alt tag to o Node Word (meta tag). Can't seem to find where the Alt tags are implemented. Is it in the 'image.module' file? Any help would be gratefully appreciated.

harrisben’s picture

I'm using 4.7.4 and want to avoid modifying image_gallery.module so have done the following:

Added code to template.php:

/**
* Catch the theme_image_gallery function, redirect through the template api
* and point Drupal to your image_gallery.tpl.php file to determine the layout
* of your image gallery pages.
*/
function phptemplate_image_gallery($galleries, $images) {
  // Pass to phptemplate, including translating the parameters to an associative array. The element names are the names that the variables
  // will be assigned within your template.
  /* potential need for other code to extract field info */
return _phptemplate_callback('image_gallery', array('galleries' => $galleries, 'images' => $images));
  }

Created new image_gallery.tpl.php and added code:

<?php
/**
 * Theme a gallery page
 */
  // We'll add height to keep thumbnails lined up.
  $size = _image_get_dimensions('thumbnail');
  $width = $size['width'];
  $height = $size['height'];

  $content = '';
  if (count($galleries)) {
    $content.= '<ul class="galleries">';
    foreach ($galleries as $gallery) {
      // $content .= '<li style="height : '.$height .'px">';
      if ($gallery->count)
        $content.= l(image_display($gallery->latest, 'thumbnail'), 'image/tid/'.$gallery->tid, array(), NULL, NULL, FALSE, TRUE);
      $content.= "<h3>".l($gallery->name, 'image/tid/'.$gallery->tid) . "</h3>\n";
      $content.= '<div class="description">'. check_markup($gallery->description) ."</div>\n";
      $content.= '<p class="count">' . format_plural($gallery->count, 'There is 1 image in this gallery', 'There are %count images in this gallery') . "</p>\n";
      if ($gallery->latest->changed) {
        $content.= '<p class="last">'. t('Last updated: %date', array('%date' => format_date($gallery->latest->changed))) . "</p>\n";
      }
      $content.= "</li>\n";
    }
    $content.= "</ul>\n";
  }

  if (count($images)) {
    $height += 75;
    $content.= '<ul class="images">';
    foreach ($images as $image) {
      $content .= '<li';
      if ($image->sticky) {
        $content .= ' class="sticky"';
      }
      $content .= ' style="height : '.$height .'px; width : '.$width.'px;"';
      $content .= ">\n";
      $content .= l(image_display($image, 'thumbnail'), 'node/'.$image->nid, array(), NULL, NULL, FALSE, TRUE);
      $content .= '<br />'.l($image->title, 'node/'.$image->nid);
      if (theme_get_setting('toggle_node_info_' . $image->type)) {
        $content .= '<div class="author">'. t('Posted by: %name', array('%name' => theme('username', $image))) . "</div>\n";
        if ($image->created > 0) {
          $content .= '<div class="date">'.format_date($image->created)."</div>\n";
        }
      }
      $content .= "</li>\n";
    }
    $content.= "</ul>\n";
  }

  if ($pager = theme('pager', NULL, variable_get('image_images_per_page', 6), 0)) {
    $content.= $pager;
  }

  If (count($images) + count($galleries) == 0) {
      $content.= '<p class="count">' . format_plural(0, 'There is 1 image in this gallery', 'There are %count images in this gallery') . "</p>\n";
  }

  return $content;
?>

When I navigate to my galleries, nothing displays though. Can anyone tell me what I'm doing wrong?

harrisben’s picture

Nothing I do, even duplicating what someone else says works for them in 4.7, works. I don't want to edit the module directly, can anyone help?

keathmilligan’s picture

I know this is really old and I'm sure the OP found a solution, but in case anyone else runs into this issue...

You need to replace the "return $content" at the end with "print $content". It's an easy error to make if you start by copying the original implementation from the image gallery module.

harrisben’s picture

Being a total noob in terms of php, I didn't know that change is needed.

elv’s picture

I've tried to display the images in chronological order, but couldn't find a way... Is there a good way (via template files) to modify the node list order?

Anonymous’s picture

The image_gallery.tpl.php recieves an array ($images), then you can use the array_reverse function from PHP to put it in order.

  $images=array_reverse($images);

That's what I use and it works fine, except if you use the sticky flag on your image nodes.

If you use the sticky flags on image nodes, and still wants to force a chronological order, you need to :

  • get the key list (array_keys($images))
  • do a query like SELECT nid FROM node WHERE nid IN (imageskeys) ORDER BY sticky DESC, created ASC
  • you now have the nids in the wanted order, just loop over this list instead of over $images
elv’s picture

Thanks for the tip, but it seems it doesn't work as expected, it reverses the order of the images on a given page, but not the order of ALL the images.
Say, I have 6 nodes per page, and a total of 9 nodes to display.
Without any modification they will be listed on two pages as:
9 8 7 6 5 4
3 2 1
And with the array_reverse as:
4 5 6 7 8 9
1 2 3
And I'm trying to do this:
1 2 3 4 5 6
7 8 9

Maybe I could use it at a higher level? But I wonder if it can be done in a theme file.

patchak’s picture

Maybe using views integration with images and the grid bonus view to redirect your taxonomy links to your custom view?

elv’s picture

"redirect your taxonomy links to your custom view"

Looks like I still have things to learn with views... Do you mean it can be done automatically for taxonomy terms? I'll investigate tonight. Thx!

patchak’s picture

hey,

http://www.lullabot.com/articles/how_to_build_flickr_in_drupal

On this article, in the section 3 Theme o rama, you'll find details about how to actually redirect taxonomy links to a custom view. I'm actually planning to use it (redirecting image links to custom gallery) myself in a project in the next two weeks, so I'll keep you posted on what I find and vice versa I hope ;)

cya

elv’s picture

OK I found how to "redirect" the taxonomies to a view, using the "arguments" settings on "Taxonomy term name".
Works well with node dates, so I can set the order to ascending or descending. Great!

Now I also need my users to reorder nodes manually if they want to. The nodes would then be ordered by "order number" then by date.
So I created a Vocabulary named "order", with numbers as terms: 1,2,3, etc.
It won't work, Views seems to use the term weights only, whereas the help text says that "This will sort nodes by taxonomy weight and name". Or more likely, I misunderstood that line ;)

I could use node_weight module, but the weights go from -x to +x (with a max of 40) when I'd like a range of something like 0 to 100.

patchak’s picture

well... can't help you on that one sorry!

seakayjay’s picture

I've followed the instructions at http://drupal.org/node/41257 for version 5. I managed to theme the image gallery page. However I would like to a comment link right below each of the thumbnails. The base_url won't print. Please help me check out the code. See below:

$content .= '<br /><a href="'.$base_path.'/comment/reply/'.$image->nid.'#comment-form" class="comment-link">Add comment ('.$image->comment_count.')</a>';

The problem I'm facing now is that I'm not able to get the base_url to be inserted to the url. I know that I can type in the url manual but I will be better if can insert the $base_path into the url.

Any help plz?

mokargas’s picture

This doesn't work for me on 5.2, I get this error:

Fatal error: Call to undefined function _image_get_dimensions() in /Applications/xampp/xamppfiles/htdocs/site/themes/new_theme/image_gallery.tpl.php on line 204

jphelan’s picture

I get the same error as denizengt but on line 2

astroboy’s picture

quite simple, but found it in another thread :

replace

_image_get_dimensions()

by

_image_get_sizes()

rad1964’s picture

In order for the image gallery formatting template to work for me:

Line #2

Change: $size = _image_get_dimensions('thumbnail'); [to] $size = _image_get_sizes('thumbnail');

Line #38

Change: format_name ($image) [to] theme_username($image)

And the new formatting changes now work.. This is in Drupal V. 5.2 .

RAD

jazbek’s picture

Thanks RAD that sorted me out. Appreciate your help.

dnewkerk’s picture

In my case, I had to make 2 additional small changes to image_gallery.tpl.php in order to get it working... I wanted to mention them here in case anyone else runs into the same thing.
My configuration includes: Drupal 5.2 and Image 5.x-1.5

When I added the Drupal 5 code from http://drupal.org/node/41257 and applied the changes to Lines 2 and 38 mentioned above, I loaded mysite.com/image/tid/1 and the Posted by: user name portion's html tags were printing out on the page and the link didn't work. I checked the similar line in the current image_gallery.module file, and it seems the parts in Line 38 that says @name needs to be changed to !name ... just change both instances of @name in Line 38 and it should work.

Alternately, if you prefer not to display the "Posted by" part with every image, just completely delete Lines 37 though 40.

-- Dave
absolutecross.com

swedev’s picture

hi,

how can i sort the images? or how are the images displayed?

thanks!
-will

joachim’s picture

Install the latest version of the module, and install Views.
The galleries are now produced as views, so you can customize the view to sort in any way you like.

swedev’s picture

Hi,

thanks for your reply.
Are you referring to a separate module named "Views"
or the two INC files included in the Image folder named: "views" and "view_defaults"?

if for the latter, how do i do that?

thank you!
-will

joachim’s picture

The module called Views.
Those two INC files contain code that will work with it.

OutCast’s picture

Is it possible to show the path or url to each image like
<img src='http://URLTOIMAGE.com/800x600.jpg' alt=SOME NAME/>
so it can be clicked on and pasted on another forum or website?
have looked everywhere how to do this and can find nothing :(

ggarry’s picture

This is what works for me with drupal 5.7 and image 5.x-1.7 the code at http://drupal.org/node/41257 made my sub albums disappear when adding a photo to a particular album/gallery where the sub album was located.

<?php
drupal_add_css(drupal_get_path('module', 'image_gallery') .'/image_gallery.css');
$size = _image_get_sizes('thumbnail');
  $width = $size['width'];
  $height = $size['height'];



  $content = '';
  if (count($galleries)) {
    $content .= '<ul class="galleries">';
    foreach ($galleries as $gallery) {
      $content .= '<li class="clear-block">';
      if ($gallery->count) {
        $content .= l(image_display($gallery->latest, IMAGE_THUMBNAIL), 'image/tid/'. $gallery->tid, array(), NULL, NULL, FALSE, TRUE);
      }
      $content .= "<h3>". l($gallery->name, 'image/tid/'. $gallery->tid) ."</h3>\n";
      $content .= '<div class="description">'. check_markup($gallery->description) ."</div>\n";
      $content .= '<p class="count">'. format_plural($gallery->count, 'There is 1 image in this gallery', 'There are @count images in this gallery') ."</p>\n";
            // start: sub-gallery links
      $children = taxonomy_get_children($gallery->tid);
      if(count($children)) {
        $content.= '<div style="font-weight: bold;">Sub-galleries:</div><ul class="subgalleries">';
        foreach($children as $child) {
          $content.= '<li>'.l($child->name, 'image/tid/'.$child->tid).'</li>'; 
        }
        $content.= "</ul>\n";
      }
      // end: sub-gallery links
      
      if ($gallery->latest->changed) {
        $content .= '<p class="last">'. t('Last updated: %date', array('%date' => format_date($gallery->latest->changed))) ."</p>\n";
      }
      $content .= "</li>\n";
    }
    $content .= "</ul>\n";
  }

  if (!empty($images)) {
    $content .= '<ul class="images">';
    foreach ($images as $image) {
      $content .= theme('image_gallery_img', $image, $size);
    }
    $content .= "</ul>\n";
  }

  if ($pager = theme('pager', NULL, variable_get('image_images_per_page', 6), 0)) {
    $content .= $pager;
  }

  If (count($images) + count($galleries) == 0) {
      $content .= '<p class="count">'. format_plural(0, 'There is 1 image in this gallery', 'There are @count images in this gallery') ."</p>\n";
  }

 print $content;

?>
mariagwyn’s picture

I have two questions.

First:
The code at the end of the above code does not return a count, but instead says "There are 0 images in this gallery," even though there are images in the gallery:

  If (count($images) + count($galleries) == 0) {
      $content .= '<p class="count">'. format_plural(0, 'There is 1 image in this gallery', 'There are @count images in this gallery') ."</p>\n";
  }

Second:
I would like to add a count to the sub-gallery, like this:
Gallery of People (there are 7 images in this gallery)
Subgalleries: happy people (3), sad people (4).

How do I do this?

Thanks,
Maria

jessejesse’s picture

So i have added the template.php, as well as the image_gallery.tip.php, and the image_gallery.css files to my theme directory... for some reason, changes I make to the css file, do nothing. Any ideas?

cheers,
jesse

jorisx’s picture

I'm trying to build my own custom node-image-gallery.tpl files for 6.1
did anyone else test this already with 6.1 ?

Any help on building a custom image.tpl.php for drupal 6.1 ?

ggarry’s picture

Not sure, the code I pasted above was ripped straight out of image_gallery.module (changing return $content; to print $content;) so maybe the same can be done with 6.

jorisx’s picture

Copied the code from image_gallery.module which workes nice :)
now some fine-tune-ing
creating a custom pager like [1] [2] [3] [4] etc

I've found
theme('pager', NULL, variable_get('image_images_per_page', 6), 0))
but can't findout where/how to customize this ...

and I would like to disable the image link
$content .= l(image_display($image, IMAGE_PREVIEW), 'node/'. $image->nid, array('html' => TRUE));
I can't find where or what to disable the link

Http://www.reloadmedia.com

FPJ’s picture

I have a question, is it possible to set a default taxonomy term for each gallery?

I don’t like it when the image module is creating for every gallery a new taxonomy term.

joachim’s picture

A gallery *is* a taxonomy term.

radj’s picture

I have an additional custom Image Size labeled "Custom". How do I make the gallery use that image instead of the thumbnail?

vantage.krishna’s picture

Hi all,

i am trying to overriding image gallery with default layout. with following code

function phptemplate_image_gallery($galleries, $images) {
   return theme_render_template('path/to/your/theme/image_gallery.tpl.php', array('galleries' => $galleries, 'images' => $images));
}

i did added this code in my template.php file with in my theme directory and then make

image_gallery.tpl.php file in same folder and write these code

  drupal_add_css(drupal_get_path('theme', 'name_of_your_theme') .'/image_gallery.css');

  $size = image_get_sizes(IMAGE_THUMBNAIL);

  $content = '';
  if (count($galleries)) {
    $content .= '<ul class="galleries">';
    foreach ($galleries as $gallery) {
      $content .= '<li class="clear-block">';
      if ($gallery->count) {
        $content .= l(image_display($gallery->latest, IMAGE_THUMBNAIL), 'image/tid/'. $gallery->tid, array('html' => TRUE));
      }
      $content .= "<h3>". l($gallery->name, 'image/tid/'. $gallery->tid) ."</h3>\n";
      $content .= '<div class="description">'. check_markup($gallery->description) ."</div>\n";
      $content .= '<p class="count">'. format_plural($gallery->count, 'There is 1 image in this gallery', 'There are @count images in this gallery') ."</p>\n";
      if ($gallery->latest->changed) {
        $content .= '<p class="last">'. t('Last updated: %date', array('%date' => format_date($gallery->latest->changed))) ."</p>\n";
      }
      $content .= "</li>\n";
    }
    $content .= "</ul>\n";
  }

  if (!empty($images)) {
    $content .= '<ul class="images">';
    foreach ($images as $image) {
      $content .= theme('image_gallery_img', $image, $size);
    }
    $content .= "</ul>\n";
  }

  if ($pager = theme('pager', NULL, variable_get('image_images_per_page', 6), 0)) {
    $content .= $pager;
  }

  if (count($images) + count($galleries) == 0) {
      $content .= '<p class="count">'. format_plural(0, 'There is 1 image in this gallery', 'There are @count images in this gallery') ."</p>\n";
  }

  print $content;

then i clear my cache from admin.

and refresh page. blank page showing now

plz help me.