I have a view that pulls together a specific content type. I have an image field in that content type that is getting displayed in a grid within the view.

I want each image to point to an external site. But I can't figure out how to make this work.

In a perfect world, the content type would have two custom fields. One for the image, and one for the url/link. Then, in the view I would be able to use the "Link Image To" drop down for the Image field.

Thanks in advance for any help.

Comments

indigetal’s picture

I'm not sure exactly how to go about redirected the url path linked to the image field but for starters, or maybe as an alternative you could download the link module @ http://drupal.org/project/link, then add a link field to your content type and pull that into the view with Format, Field: Add > Content: Link. Sorry, that's all I've got.

nkuebelbeck’s picture

I did that. The only way is to have the link below/above the image. IMHO that just looks 3rd grade'ish :)

more google time for me.

ryivhnn’s picture

I'm assuming you're using Views to make the views :)

Set the higher field to not display and rewrite the output of the lower field. So for example if you have your image field followed by your url field, set the image field to not be displayed, then rewrite the output of the url field to something like:

<a href="[field:url]"><img src="[field:image]" /></a>

The rewrite thing will tell you what the tokens actually are.

works at bekandloz | plays at technonaturalist

nkuebelbeck’s picture

What type of field should I use for the link? This ->http://drupal.org/project/link?

ryivhnn’s picture

You could make a content type with a text field (plain text for the url, use the title as the link description) and an image field easily enough :)

works at bekandloz | plays at technonaturalist

nkuebelbeck’s picture

I added another content type of Link type(after installing the module)

I put the external link in that field. Its nice cause it offers some validation..

in the view. Add the image field,then the link field(make sure you set the format to "URL, as plain text")

ORDER IS IMPORTANT. You can't use the field_image unless it's before the link...

Then in the link field view area, click on the "REWRITE RESULTS" area. Check the "Rewrite the output of this field" checkbox.

Then I did this <a h ref=[field_link]>[field_image]</a> no quotes and it worked.

_jmk_’s picture

I've followed exactly this process, but still encountering issues.

The clickable image shows up in the views preview pane with the correct external link, making me think that the View Fields and Criteria are set up correctly to allow external linking from my View.

However, this doesn't carry across to the actual page. The Title and Summary text description are there for the Link type Content but there is no image. The brick links to the Content, rather than the external link that I would like the image to link to.

I know that's sort of a different issue but does anyone know why a view that works in preview isn't functioning on the actual site?

(apologies for the long bump but I found the discussion here really useful so though somebody might be able to help)

makt’s picture

I have my images linked to an external URL in views but every once in a while I will have an image that does not have an external URL associated with it. Right now, if I click on that image it will re-open the page I am on in a new tab.

Is there any way to set views so that if I do not have a URL defined in the Link field of my content type, it will not make my image clickable?

zareen’s picture

Thank you so much for this. Worked for me. I had to enter my image first, then enter the link field.

Make sure you actually get your link field and not the link to image or link to user field which can look very much the same unless you give your outside link a unique name like my_link, or outsideweb_link.

Thanks

kaka1986’s picture

my link said: thank u too

simdoanhnhanvn’s picture

invites you to visit the website selling my beautiful sim in Vietnam
sim so dep