How do I make a node link directly to its file contents in DRUPAL 6?
Asked Answered
G

2

10

I have a menu item called "Products" which when clicked displays all nodes created by the "product" content type. Every "product" node has a file attachment field with a file attached.

If I click on a "product" node, it takes me to the node as expected and I can see all the fields on the node, including the PDF field:

enter image description here

I want to hover over the "Products" menu link, then see the different products as a dropdown in the menu and when a product is clicked I want it to NOT go to the node, but rather open the PDF attached to the node So instead of showing e.g /product/african-decor ... it must go to product/african_decor.pdf which is attached to the node:

enter image description here

Geordie answered 29/10, 2015 at 7:18 Comment(2)
The tag is Drupal 7, the heading says Drupal 6 - so what is your version? Beside of that, I don't really get what you want to do. You want to link to a field of the node? Like an anchor?Cardigan
Thank you I made a mistake, fixed it.Geordie
I
4

There are a couple of ways this can be achieved.


You can use the Menu Token module which allows you to use various fields in your menu paths. When building the token pattern you may need to create an absolute URL using the [site-url] token.

Also make sure the uses tokens checkbox is ticked.


This way is slightly less elegant.

Assuming you don't want to actually visit the product content type and will always download the PDF, you can overwrite the template for the product content type and redirect to the PDF URL.

You'd need to create

node--product.tpl.php

And replace the contents with

header("Location: " . $pdf_field);

// $pdf_field might be $node->field_pdf[0]['value'];
Interstellar answered 13/11, 2015 at 17:48 Comment(0)
C
1

You can implemement hook_taxonomy_menu_path with a custom module an override the base based on the nodes associated with the term. In the callback, return the path of the attachment in the node.

  • Given the fact that every term only has one node
  • Given the fact that every node has only one attachment
Cardigan answered 12/11, 2015 at 13:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.