向 Drupal 中的每个节点添加动态 URL(或按钮)
我使用 CCK 创建了一个“旅行优惠”内容类型,它基本上只列出了旅行套餐的详细信息。
我的问题是如何在每个节点上有一个按钮或链接(当用户查看它时),该按钮或链接将链接到包含当前节点标题的网址(例如:example.com/requestQuote/Title_Of_This_Node)。
我还没有实现我的系统,所以我可以随意更改内容类型以包含按钮字段或类似的内容......
I've used CCK to create a 'Travel Offer' content-type which 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 (eg: example.com/requestQuote/Title_Of_This_Node).
I haven't implemented my system yet so I am free to change the content-type to include a button field or something like that...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现此目的的最简单方法是将
node-your_content_type_name.tpl.php
文件添加到主题文件夹中。 (如果您以前没有这样做过,您所需要做的就是创建一个 node.tpl.php 的副本,并将副本重命名为node-your_content_type_name.tpl.php
)'$title'变量在节点模板中可用,因此应该很容易编写一些 PHP 来打印出适当的链接目标。
编辑:
现在,如果您想变得更奇特一点,您可以构建链接来引用未别名的节点页面(“example.com/requestQuote/node/11569”或其他)并通过 Drupal 方便的
l 提供它()
函数来构建超链接。这样做的优点是,即使标题更改,您也不必担心链接也会更改,即使
l()
会自动更新向用户显示的实际超链接。这可能也会使“example.com/requestQuote”页面上的自定义编码变得更加容易,因为您可以直接使用节点 ID,而不需要解析标题。
The easiest way to accomplish this would be by adding a
node-your_content_type_name.tpl.php
file into your theme folder. (If you haven't done this before, all you need to do is create a duplicate of node.tpl.php and rename the copy tonode-your_content_type_name.tpl.php
)The '$title' variable is available within the node template, so it should be easy to craft a little bit of PHP to print out the appropriate link target.
Edit:
Now, if you want to get a little bit fancier, you could build the link to reference the unaliased node page ('example.com/requestQuote/node/11569' or whatever) and feed it through Drupal's handy
l()
function to build the hyperlink.The advantage here is that you won't need to worry about the link changing if the title changes, even though
l()
will automatically update the actual hyperlink that's displayed to the user.This will probably make the custom coding on your 'example.com/requestQuote' page a lot easier too, since you can work directly with the node ids and don't need to parse titles.