How to link image in the slide to a node?

To link the image in the slide to the node you can use the l() function like below:

l($text, $path, $options = array())

if ($vars['imgcache_slide'] <> '<none>' && module_exists('imagecache') &&  is_array(imagecache_presets())){
  $slider_items[$key1]['slide_image'] = 
  l(theme('imagecache', 
          $vars['imgcache_slide'], 
          $filepath,
          check_plain($result->node_title)),                  
    'node/' . $result->nid,
    array('html' => TRUE,) // needed, Whether the title is HTML, or just plain-text. TRUE for HTML
  );
}
else {          
  $slider_items[$key1]['slide_image'] = 
  l('<img src="' . base_path() . $filepath . '" alt="' . check_plain($result->node_title) . '"/>',                  
    'node/' . $result->nid,
    array('html' => TRUE,) // needed, Whether the title is HTML, or just plain-text. TRUE for HTML
  );
}          

Comments

beckun

Finally found how to link image in the slide to a node, I have been quite busy at essay-writing-service.reviews and they have been supporting so many of time, The link below is so much brilliant and worth trying, Have a great day ahead

where should this be placed ?

hi

i need some help - drupal 6 with ddblock as news items, i just want to link the image to the node - same as the read more link. i guess i should put it in the template.php file where i put the ddblock preprocess functions code but where ??

thanks.

RE: where should this be placed

The handling of the image field should be replaced with this code.

Normal code

            if (module_exists('imagecache') && is_array(imagecache_presets()) && $vars['imgcache_slide'] <> '<none>'){
              $slider_items[$key1]['slide_image'] = 
              theme('imagecache', 
                    $vars['imgcache_slide'], 
                    $filepath,
                    check_plain($result->node_title));
            }
            else {          
              $slider_items[$key1]['slide_image'] = 
                '<img src="' . base_path() . $filepath . 
                '" alt="' . check_plain($result->node_title) . 
                '"/>';     
            }          
 

replace with

if ($vars['imgcache_slide'] <> '<none>' && module_exists('imagecache') &&  is_array(imagecache_presets())){
  $slider_items[$key1]['slide_image'] = 
  l(theme('imagecache', 
          $vars['imgcache_slide'], 
          $filepath,
          check_plain($result->node_title)),                  
    'node/' . $result->nid,
    array('html' => TRUE,) // needed, Whether the title is HTML, or just plain-text. TRUE for HTML
  );
}
else {          
  $slider_items[$key1]['slide_image'] = 
  l('<img src="' . base_path() . $filepath . '" alt="' . check_plain($result->node_title) . '"/>',                  
    'node/' . $result->nid,
    array('html' => TRUE,) // needed, Whether the title is HTML, or just plain-text. TRUE for HTML
  );
}      

When you have additional question, please make a support request in the issue queue of the module at: http://drupal.org/project/issues/ddblock

Thanks for this information

Thanks for this information and this fabulous module.

It would be helpful if the preprocess functions included a version of the template.php snippet with this inserted in the right place, for those who don't want to use the Read More button to link to the node. Any chance of that?thanks!

Re: Thanks for this information

I don't understand what your request is.
Can you be more clear, so I can help you better?

I would like to see this code

I would like to see this code inserted as well. Can we just put it anywhere in the preprocess functions? Does it go in both or only one? Do we need to change the theme files as well?

How do I link to a different node?

I've tried using this code in my template.php file in place of:

if (module_exists('imagecache') && is_array(imagecache_presets()) && $vars['imgcache_slide'] <> '<none>'){
              $slider_items[$key1]['slide_image'] = 
              theme('imagecache', 
                    $vars['imgcache_slide'], 
                    $filepath,
                    $result->node_title);
            }
            else {          
              $slider_items[$key1]['slide_image'] = 
                '<img src="' . base_path() . $filepath . 
                '" alt="' . $result->node_title . 
                '"/>';     
            }        

But it links to the node that displays the slide. I would like to link to a different page.

Re: How do I link to a different node?

Have a look at the How to: How to link Read more... button to another page instead of the node

This same URL field can be used for linking the slide to another page.

Hope this helps you further, please let me know.

Tried this

So I tried this code but a number of issues have arised, of which I believe stem from one particular line of code:

when I copy and paste this code, the images are linked to pages BUT they are no longer in a Slideshow but instead layed out below each other.

When I remove HTML"True" from the code though, it goes back to normal, but the "src" link shows instead of the image. How can I get it so that only the "src" link is recognized as true html and not ruin the rest of my images.

below is my code:

 if (module_exists('imagecache') && is_array(imagecache_presets()) && $vars['imgcache_slide'] <> '<none>'){
              $slider_items[$key1]['slide_image'] = 
              l(theme('imagecache', 
                    $vars['imgcache_slide'], 
                    $filepath,
                    check_plain($result->node_title)),
					 $result->node_data_field_pager_item_text_field_url_value);
            }
            else {          
              $slider_items[$key1]['slide_image'] = 
                l('<img src="' . base_path() . $filepath . 
                '" alt="' . check_plain($result->node_title . 
                '"/>'), $result->node_data_field_pager_item_text_field_url_value);      

Re: tried this

The end tag of the img is plain text:

check_plain($result->node_title . '"/>')
should be:
check_plain($result->node_title) . '"/>'

Adjusted in the original post.

if ($vars['imgcache_slide'] <> '<none>' && module_exists('imagecache')
&&  is_array(imagecache_presets())){
 
  $slider_items[$key1]['slide_image'] =
  l(theme('imagecache',
          $vars['imgcache_slide'],
          $filepath,
 
check_plain($result->node_title)),                 
    'node/' . $result->nid,
    array('html' => TRUE,) // needed, Whether the title is HTML, or
just plain-text. TRUE for HTML
  );
}
else {         
  $slider_items[$key1]['slide_image'] =
  l('<img src="' . base_path() . $filepath . '" alt="' .
check_plain($result->node_title) .
'"/>',                 
 
    'node/' . $result->nid,
    array('html' => TRUE,) // needed, Whether the title is HTML, or
just plain-text. TRUE for HTML
  );
}