Add dynamic url (or button) to every node in Drupal

I used CCK to create "Travel Offer" content that basically just lists the details for a travel package.

My question is how to have a button or link on each node (when the user views it) that will link to a URL that includes the title of the current node (ex: example.com/requestQuote/Title_Of_This_Node).

I haven't implemented my system yet, so I can freely change the content type to include a button field or something ...

+2


a source to share


1 answer


The easiest way to achieve this is to add the file node-your_content_type_name.tpl.php

to your theme folder. (If you haven't already done so, all you need to do is duplicate node.tpl.php and rename the copy to node-your_content_type_name.tpl.php

)

The variable '$ title' is available in the node template, so it should be easy to create some PHP to print the corresponding target link.

Edit:



Now if you want to get a little involved, you can create a link to link to the unaliased node page ('example.com/requestQuote/node/11569' or whatever) and pass it through Drupal A handy function l()

to create a hyperlink.

The advantage here is that you don't have to worry about changing the link if the title changes, although it l()

will automatically update the actual hyperlink shown to the user.

This will probably make it easier to set up custom coding at example.com/requestQuote, as you can work directly with node IDs and not need to parse the names.

+2


a source







All Articles