我可以每月自动将 Drupal 菜单项链接到不同的节点吗?
我有一个内容类型,其中一个字段将节点与月份和年份相关联。我希望主菜单中的一个项目始终链接到与当前月份关联的节点。我该怎么做?似乎没有一个钩子可以让我在打印之前更改链接......
I have a content type with a field that associates a node with a month and year. I want an item in my main menu to always link to the node associated with the current month. How do I do this? There doesn't seem to be a hook that will let me change the link before it's printed...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许如果您使用 menu_link_save,我不是 100% 确定这是否适合您,但理论上它应该只是添加该项目
希望它有帮助。
Maybe if you dynamically add the menu item with menu_link_save, I'm not 100% sure if this will work for you, but in theory it should just be adding the item
Hope it helps.
我将创建一个自定义模块,该模块使用hook_menu(),然后创建一个确定当前月份节点的函数并使用 drupal_goto 将用户重定向到该节点。
这样您就不必担心挂接和修改菜单。
I would create a custom module that creates a path such as
current-month
using hook_menu(), then create a function that determines the current months node and use drupal_goto to redirect users to that node.This way you don't have to worry about hooking into and modifying the menu.