Add Links to Fields in Views – Drupal 7

drupal-views-links

drupal-views-linksThis blog post is the answer to a common request we get from people learning how to use Views.

The question is: “How do I automatically add a link to a field”?

The answer is straightforward, once you know how.

Imagine that you have a content type that looks like the image below. You have an active link using the Link module and also some other fields.

media_1397067314201.png

Now imagine that we’re using Views to show some of items in that content type. Here’s a photo gallery using Views. If you don’t know how to do this, use our tutorial “Creating a Photo Gallery in Drupal 7“.

media_1397067634329.png

Now let’s show you to automatically add links.

In this example, we’re going to automatically link the Movie Poster field to the “Official Website” field.

Inside our view, the image below shows how the fields look currently. We have a Title and Movie Poster field.

media_1397067669374.png

We’re going to add the Movie Poster field.

  • Click “Add” next to “Fields”
  • Choose “Official Website”
  • Check the “Exclude from display” box because we don’t want this to be visible.

media_1397067714138.png
  • Save the field. It should show at the bottom of the three fields.
  • Click the “Rearrange” button under “Add”

media_1397067799410.png
  • Rearrange the fields so that the Official Website field is before the Movie Poster field.

media_1397067837174.png
  • Click the Move Poster field.
  • Check the “Output this field as a link” box.

media_1397067876071.png
  • Scroll down to the Replacement Patterns area.
  • Find the replacement pattern for the Office Website field.

media_1397067887537.png
  • Copy the replacement into the “Link path” field:

media_1397067914966.png
  • Save the field and then save the view.

You’ve finished and your movie posters will be automatically linked to the official website.

Author

  • Steve Burge

    Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.

0 0 votes
Article Rating
Subscribe
Notify of
4 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Rodolfo
Rodolfo
10 years ago

Great post, thks.

sscarduzio
sscarduzio
8 years ago

Thanks for this post, very useful. What about if I want the link to point to the edit form for the current node? Is this possible without the link module btw?

lumas71
lumas71
7 years ago

Great post!

VO
VO
4 years ago

For Drupal 8?

4
0
Would love your thoughts, please comment.x
()
x