0

I'm using Panels to generate my front page. In one of the panes in my panel layout, I want to have an image which is linked to a given URL. The image and URL are going to be managed by my users.

I've been told that the Link module will give me a field type for URLs., and the Link Image Formatter module will let me link images to URLs; but I can't find any documentation on how to actually use the link image formatter. (EDIT: It turns out the Link Image Formatter wasn't about making href links, but just including images from a different domain.. or something, I'm confused.)

I've tried creating a content type with an image field, and a link field, but I can't find any way to connect them, or any way to associate an image with the link field.

EDIT: The URL may be internal to the drupal site or it may be external. These image/link combinations will be created and managed by the user through drupal. There may be 4 of them on the front page, but I may need to use them more later on throughout the site. They aren't unique to each user, I'll only have one admin user who will be posting all of the content on the site.

I want the user to add a piece of content. They'll upload an image and they'll define the URL they want that image to link to. Then in one of my Views/blocks, I can select that content type and show it in a certain region. It'll just show the image, but if a user clicks on the image, it'll take them to the specified URL which may be external to the site.

This seems like a wheel that should already have been invented, but I'm having trouble finding them.

How can I achieve this?

EDIT: I figured out what I was doing wrong... I think the person who suggested the Link Image Formatter module to me may have hastily picked the wrong url when they sent it to me and really meant to send the Link Image FIELD module which does exactly what I expected.

2
  • 1
    Could you be more specific about what you're trying to do? For example, is the URL always going to link to somewhere else within the website, or could it be an external URL as well? How many of these will there be? Will all users be able to manage these, and will they be unique for each user? May 30, 2012 at 5:21
  • Hi Patrick, I've updated my question to hoping answer yours. May 30, 2012 at 16:28

2 Answers 2

3

you can load a image from a node.

 $prev_node = node_load($prev->nid); 
    $image = field_get_items('node', $prev_node, 'field_image');
     $img = field_view_value('node', $prev_node, 'field_image', $image[0], array(
      'type' => 'image',
      'settings' => array(
      'image_style' => 'thumbnail',
      'image_link' => 'content',
     ),
   ));

then if you get the image, linking image to a certain url can be easily done by

 $options = array(
            'html' => TRUE,
            'attributes' => array(
                'title' => $prev_node->title
            )
 );     
 $output = l($img, "your url", $options);
 print render($output);
2
  • Where would I put this code? May 30, 2012 at 16:45
  • didn't work for me. Outputted word 'Array'. What did work (D7): not using l() function but directly rendering $img, like so: print render($img). The setting 'image_link' => 'content' as above will make the image link to the node. If you change this to 'image_link' => 'file', it will link to the image file itself. see api.drupal.org/api/drupal/modules%21image%21image.field.inc/… Dec 27, 2018 at 17:30
2

I figured out what I was doing wrong... I think the person who suggested the Link Image Formatter module to me may have hastily picked the wrong url when they sent it to me and really meant to send the Link Image FIELD module which does exactly what I expected.

Link Image Field module is the right one. It let's you create a field in your content type of type "Link Image" and when you add content and upload an image, it asks you for the URL you want to link it to. I knew this had to have been solved before me, I was just using the wrong, but similarly named, module.

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.