I created a custom link field for my Product content type using Drupal 6 and Ubercart 2. Now instead of linking the Product image in the Product site to itself or show it as a slideshow I would like to create a link to the URL of the given field.

I found the function that displays the product image, which is called 'theme_uc_product_image' and replaced

 $output .= '<a href="'. imagecache_create_url('product_full', $first['filepath']) .'" title="'. $first['data']['title'] .'"';


$destination_url = $node->field_direct_shop_link[0]['url']; 
$output .= '<a href="'. $destination_url .'" title="'. $first['data']['title'] .'"';

but it didn't work out!

Any ideas on how to solve this?

Thanks a lot in advance. Best, Manuel

  • can you cut and paste the HTML that it did generate? that might help in figuring out what part didn't work. but a first guess is that since this is D6, it isn't complaining about $node not being defined inside the theme function, but that is just a guess at this point.
    – Jimajamma
    Commented Aug 16, 2012 at 14:01
  • sorry for my late reply. this is the html which it generated: <div class="product-image"><div class="main-product-image"><a href="" title="Test Product"> it totally ignored my url! so it probably is because $node is not defined. do you know if there's an easy way to solve this?
    – manue1
    Commented Aug 22, 2012 at 13:39

1 Answer 1


Digging into Ubercart, this is the theme function you are talking about:

 * Formats a product's images.
 * @ingroup themeable
function theme_uc_product_image($images, $teaser = 0, $page = 0) {
  static $rel_count = 0;

  // Get the current product image widget.
  $image_widget = uc_product_get_image_widget();

  $first = array_shift($images);

  $output = '<div class="product-image"><div class="main-product-image">';
  $output .= '<a href="'. imagecache_create_url('product_full', $first['filepath']) .'" title="'. $first['data']['title'] .'"';
  if ($image_widget) {
    $image_widget_func = $image_widget['callback'];
    $output .= $image_widget_func($rel_count);
  $output .= '>';
  $output .= theme('imagecache', 'product', $first['filepath'], $first['data']['alt'], $first['data']['title']);
  $output .= '</a></div><div class="more-product-images">';
  foreach ($images as $thumbnail) {
    // Node preview adds extra values to $images that aren't files.
    if (!is_array($thumbnail) || empty($thumbnail['filepath'])) {
    $output .= '<a href="'. imagecache_create_url('product_full', $thumbnail['filepath']) .'" title="'. $thumbnail['data']['title'] .'"';
    if ($image_widget) {
      $output .= $image_widget_func($rel_count);
    $output .= '>';
    $output .= theme('imagecache', 'uc_thumbnail', $thumbnail['filepath'], $thumbnail['data']['alt'], $thumbnail['data']['title']);
    $output .= '</a>';
  $output .= '</div></div>';

  return $output;

First off, I hope you didn't go in there and start hacking away, but rather copied the above to your theme's template.php file and renamed it YOURTHEME_uc_product_image() and made your modifications there :) But, either way, from the declarations of this theme function, the only data you have to work are in the $images argument plus anything uberfunky returned by ub's image_widget. You might want to throw in some debug code to see if anything in there is what you are looking for like this:

drupal_set_message('<pre>' . print_r($images, TRUE) . '</pre>');

at the start of your copied function. Just remember to clear your caches/theme registry so drupal sees your function.

  • Haha, no no I've copied the function to my template.php! So I threw in the debug code and got the array printed. But there's no information related to my URL. I've also added $node = node_load($nid); this here, but still no changes..
    – manue1
    Commented Aug 22, 2012 at 14:55
  • if this is being displayed on a node page, you are sitting on www.yoursite.com/node/#nid#, so, you could grab the nid by doing something like if (arg(0)=='node' && is_numeric(arg(1)) { $node=node_load(arg(1)); }
    – Jimajamma
    Commented Aug 22, 2012 at 16:00
  • so the node type is a Product (ubercart) and it's sitting on a url like this www.mysite.com/content/my-test-product! but this page has still got a nid right? does anyone know how to access it from within my theme_uc_product_image function? is it possible to do something like this function theme_uc_product_image($nid, $images, $teaser = 0, $page = 0) ?
    – manue1
    Commented Aug 23, 2012 at 12:42
  • Not to get into a deep discussion here, but if content/my-test-product is a node, that is an alias to it, and its system path is really node/### and drupal can access it via $_GET['q'] or its arg() function and arg(1) will be the nid.
    – Jimajamma
    Commented Aug 23, 2012 at 13:28
  • ok sorry, i'm still pretty new to drupal. so i've tried the following: if (arg(0)=='node' && is_numeric(arg(1)) { $node=node_load(arg(1)); } $destination_url = $node->$field_direct_shop_link[0]['value']; $first = array_shift($images); $output = '<div class="product-image"><div class="main-product-image">'; $output .= '<a href="'. $destination_url .'" title="'. $first['data']['title'] .'"'; but then my page didn't load anymore, so there must be something wrong in the code..
    – manue1
    Commented Aug 27, 2012 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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