6

I am trying to create ads on the sidebar to my site. I have created a content type that has 2 fields; an image field, and a link field. I now want to display the ads in a view by having the image appear, and when you click on the image, it brings you to the link that was specified by the link field. I know how to do this in a block with HTML, but I want to do it dynamically through a view. Is there any way to do this?

14

Make sure the Row Style is Fields. Add both fields, link field first and then image field.

Edit the link field (in the Views UI) and check exclude from display and use the URL as plain text formatter.

Finally, edit the image field and check output this field as a link. There are replacement patterns you can use for the link destination, the link field should be available there. You will need to check use absolute path.

  • 2
    This pattern is always the same, I highly suggest using features to export the content type, fields and view for later reuse. – Capi Etheriel Aug 10 '11 at 13:21
  • I'm using drupal 7 – Ephraim Aug 10 '11 at 13:31
  • 2
    Using Views 3 terms since the question is tagged 7. There a couple other required options. For the link field, you need to use the 'URL as plain text' formatter. In the Rewrite Results for image field, in the 'output field as a link section', make sure you check 'use absolute path'. – keithm Aug 10 '11 at 13:40
  • the link field is simply text, it is not an actual hyperlink. is there a way to get the text from it, and make the image a link to the text in the link field? – Ephraim Aug 10 '11 at 13:49
  • 1
    @keithm: thanks, I have added your corrections to the answer. ephraim: the replacement pattern will be replaced by your string. you can write the link as twitter.com/[replacement_pattern] – Capi Etheriel Aug 10 '11 at 13:53
1

The Image Link Formatter module also seems to be an option.

This module is the result of the discussions around a requested feature to allow an image field to be displayed with a link to a custom URL:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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