Right now only a few fields have the option to turn itself into a link to the node, such as the node title and the view link. So if a user creates a node list displaying other fields, then the list doesn't contain any link to view that node.

For example, in my current project I'm attaching an image using imagecache to a node -- and I want to create a grid view (from views bonus pack) of just the images of each node. But there's no way to turn that image into a link to the node. I'm having to have the image and the view link, and use JavaScript work around to turn the images into links.

If we had an ability to turn any fields into a link to the node, then a user can select any fields out of nodes and turn them into a useful view.

Comments

emdalton’s picture

I agree, I need this functionality too. In my case, My clients want to be able to have a descriptive title for each node that will display with the node, but we also have a block configured which lists nodes related by taxonomy. The links in this block need to be more abbreviated. On each node, we have a "link text" field using CCK, and I can list those in the block, but not as links.

One workaround in our case, I suppose, would be to put the abbreviated text in the node title but then redefine the node display using a template to use a longer title from a different field. But I think this is an inferior solution. The default should be to use the title text.

amuro73, could you share your javascript workaround? I may need to use it in the meantime. Thanks.

amuro73’s picture

It can be done with JavaScript or jQuery.

What I did was to use Views to output the "view link" and another field (in my case, an imagecache generated image) from each node in the listing. Then I had a jQuery go through the page, look within the div of each node listing, find a link and store the href information, make the other field a link using the href stored, then make the original link invisible.

The jQuery script below only works when you have only ONE "a" and "img" tags each per node listing. Then it'll take the link information from the link and turn the image into that link, while hiding the original link.

$(document).ready(function() {
$("div.view-item").each(function(i){
//first, store the link destination from the link within that div
var link = $("a", this).attr("href");
//then wrap the image with an a tag with the link destination above.
$("img", this).wrap("");
});
$("div.view-data-node_view").hide();
});

Good luck!

amuro73

emdalton’s picture

Thanks, amuro73. The workaround I decided to go with was a computed field, which creates a link to the node using the short version of the title. Then I pull that into the view. I used the following code:

$node_field[0]['value'] = l($node->field_link_text[0]['value'], 'node/'.$node->nid);
$display = $node_field_item['value'];

However, you have to re-submit each page to fill the computed values.

Gidgidonihah’s picture

Version: 5.x-1.5 » 5.x-1.6

I agree. I've wanted this functionality many times. The computed field workaround does the job, but there shouldn't be any reason that any field could be set as a link in the view.

Any update on this?

catch’s picture

Version: 5.x-1.6 » 6.x-2.x-dev
Status: Active » Fixed

As far as I can see this is implemented in views 2.

Gidgidonihah’s picture

Beauty, thanks.

merlinofchaos’s picture

It's not really any field; it's only the core node fields. Anything beyond that will have to be done with theming.

Gidgidonihah’s picture

Merlin, why have you chosen not to allow any field?

I use auto node title to create a title from many fields, but I may want to show only one of those on the view and link it back.

For example, I want to be able to sort first name and last name separately, but if I set them up as fields, they don't link back to the node.

merlinofchaos’s picture

Because it's a lot harder than it sounds. Especially in Views 2, where it can list more than just nodes.

It's also very easy in views 2 to create a field template to do the link. Much, much easier than in Views 1.

catch’s picture

CCK fields are also doing this, fwiw (or at least the ones I checked on my dev site).

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

jeffschuler’s picture

Status: Closed (fixed) » Active

My understanding of comments #5 and #7 is that Link this field to its node should be an available option for all core node fields.

However, in Views 6.x-2.x-dev and 6.x-2.8, I'm only see that option for Node: Title.

Specifically, I'm looking to link Node: Post date back to the node -- using the alias link (as opposed to with node/[nid].)

merlinofchaos’s picture

Status: Active » Closed (fixed)

Note that if you use node/[nid] then it will automatically be converted to its alias on output.

jeffschuler’s picture

Awesome. That's good to know -- thanks Merlin.

I see now that the Node: Post date field doesn't get the Link this field to its node option because it's handled by views_handler_field_date and not views_handler_field_node...