14
               

I am kicking the tires on Drupal 7 by spinning up a test site.我正在通过旋转一个测试站点来踢 Drupal 7 上的轮胎。

I chose the Danland theme and created various pages with URL Aliases for each, but when I create the Menu link for each, I can only enter the node in the "Path" field for the menu link and not the alias. So I can only enter "node/20" and not "about-us" (the alias for the node) in the menu.我选择了 Danland 主题并为每个页面创建了带有 URL 别名的各种页面,但是当我为每个页面创建菜单链接时,我只能在菜单链接的“路径”字段中输入节点,而不能输入别名。所以我只能在菜单中输入“node/20”而不是“about-us”(节点的别名)。

I'd like the menu items to resolve to the aliases and not the nodes.我希望菜单项解析为别名而不是节点。
                       How do I do that?我该怎么做?

                                   
Improve this question 改进此问题                                     
  • 3                                
    When displayed, the menu link will use the defined path alias. Any reason why this isn't enough?显示时,菜单链接将使用定义的路径别名。这还不够的原因是什么?                                    
    – Berdir 贝尔迪尔                                     
     Apr 14, 2011 at 15:19 2011-4-14在15:19                                 
  • Mine doesn't seem to be doing that. Not sure if I'm missing some config somewhere or what - see:我的似乎没有这样做。不确定我是否在某处缺少一些配置还是什么 - 请参阅:reboot.researchvessels.org/about-usreboot.researchvessels.org/about-us                                    which works as an alias but I can't make the menu link go there. Path field only accepts external URLs or node refs.它可以用作别名,但我无法使菜单链接转到那里。路径字段仅接受外部 URL 或节点引用。                                    
    – cpuguru 中央处理器                                     
     Apr 14, 2011 at 15:25 2011-4-14在15:25                                  
  • I'm having the same problem. My "main menu" works fine with aliases. I created a new menu. This is the only that won't save aliases. Furthermore it breaks completely because when I go to "node/10" then I want to click on another page the menu links have an extra "node" so it is pointing to "node/node/10" "node/node/11" etc. If I use the absolute path then it will take me to the correct page but I want the menu to be able to automatically recognize which page is active, it doesn't recognize that the absolute URL is the path I'm on so the css class "active" isn't set properly. I have drupal 7.2我有同样的问题。我的“主菜单”适用于别名。我创建了一个新菜单。这是唯一不会保存别名的方法。此外,它完全中断了,因为当我转到“node/10”时,我想单击另一个页面,菜单链接有一个额外的“节点”,因此它指向“node/node/10”、“node/node/11”等。如果我使用绝对路径,那么它会将我带到正确的页面,但我希望菜单能够自动识别哪个页面处于活动状态,它无法识别绝对 URL 是我所在的路径,因此 css 类“活动”设置不正确。我有drupal 7.2                                    
    – user1645 用户1645                                     
     Jun 15, 2011 at 20:48 2011-6-15在20:48处                                 
       

6 Answers  6 个回答 

       
7
                   

As Berdir mentioned in the comments and Greg in his answer                            , the following methods of adding path aliases should Just Work                            ™.正如 Berdir 在评论中提到的,Greg 在他的回答中提到,以下添加路径别名的方法应该可以正常工作™。

  • Adding it on the node submission form during node creation/editing在节点创建/编辑期间将其添加到节点提交表单中
  • Using the 

    Pathauto                                

     module to automatically create path aliases使用 Pathauto 模块自动创建路径别名
  • Manually adding path aliases on 

    Configuration → Search and metadata → URL aliases                                

    在配置→搜索和元数据→ URL 别名上手动添加路径别名

Try clearing the cache from Configuration → Development → Performance                            . This should rebuild Drupal's menus and correctly show the path aliases.尝试从“配置”→“开发→性能”中清除缓存。这应该重建Drupal的菜单并正确显示路径别名。

                                       
Improve this answer 改进此答案                                         
       
4
                   

I could also be that you are browsing the site in a different language than the url alias was created for. If you create an alias while browsing in German (say), visitors browsing the site in English mode will still see node/234234 . Just a tip.我也可能是您正在使用与创建 url 别名不同的语言浏览网站。如果您在使用德语浏览时创建别名(例如),以英语模式浏览网站的访问者仍将看到 node/234234 。只是一个提示。

                                       
Improve this answer 改进此答案                                         
       
0
                   

If you assign both the path alias and the menu entry using the node add/edit form                            , then the created menu items will use the aliased paths. For simple use cases you shouldn't need to manually create aliases on the admin/config/search/path                             page or manually create menu entries on the admin/structure/menu                             page.如果使用节点添加/编辑表单同时分配路径别名和菜单项,则创建的菜单项将使用别名路径。对于简单的用例,您不需要在页面上手动创建别名,也不需要在页面上手动创建菜单项。

                                       
Improve this answer 改进此答案                                         
  • I can create the aliases and they work if I go to them directly, but I can't find a way to configure the menu to use them. The only option available seems to be "node/xx" for the Path field, and when you click on the link it shows site/node/xx in the address field and not the URL alias.我可以创建别名,如果我直接访问它们,它们就会起作用,但我找不到配置菜单以使用它们的方法。唯一可用的选项似乎是路径字段的“node/xx”,当您单击链接时,它会在地址字段中显示 site/node/xx,而不是 URL 别名。                                        
    – cpuguru 中央处理器                                         
     Apr 14, 2011 at 19:56 2011-4-14在19:56处                                     
  • @cpuguru - If you delete a node's alias and menu item, then recreate the alias and menu item from the node edit form, does the menu item still not use the alias? 
    – Greg 格雷格                                         
     Apr 14, 2011 at 20:18                                    
  • No, I just tried again with the "Partnerships" page. Deleted the Alias and the menu item and then added the "Partnerships" page, adding the Alias and adding it to the Menu and it still shows up in the menu as "node/21".不,我只是在“合作伙伴关系”页面再次尝试。删除了别名和菜单项,然后添加了“合作伙伴关系”页面,添加了别名并将其添加到菜单中,它仍然在菜单中显示为“node/21”。                                        
    – cpuguru 中央处理器                                         
     Apr 14, 2011 at 20:55 2011-4-14在20:55                                     
       
0
                   

I just tried with a new d7 installation using the Danland theme and it works properly. If you can't get it working you can always specify an external url in your menu right? Such as 'http://yourdomain.com/about-us' intead of 'node/1'我刚刚尝试使用 Danland 主题安装新的 d7 安装,它工作正常。如果你不能让它工作,你可以随时在你的菜单中指定一个外部URL,对吧?例如“node/1”的“http://yourdomain.com/about-us

                                       
Improve this answer 改进此答案                                         
       
0
                   

It appears that updating my Drupal install from Drupal 7 to the newly released Drupal 7.2 fixed the problem. It was either that or the updated SQL Server drivers that were just released which you'll need to install over the original PDO SQL Server drivers for the update scripts to work if you're updating to Drupal 7.2.似乎将我的Drupal安装从Drupal 7更新到新发布的Drupal 7.2解决了这个问题。它要么是刚刚发布的更新的 SQL Server 驱动程序,如果要更新到 Drupal 7.2,则需要在原始 PDO SQL Server 驱动程序上安装这些驱动程序,以便更新脚本正常工作。

Either way, now the aliased URL shows up when I click on a menu link. So it could be either the code changes in Drupal core 7.2 OR the SQL Server driver updates. I am not 100% sure which one it is.无论哪种方式,现在当我单击菜单链接时都会显示别名 URL。因此,它可能是 Drupal 核心 7.2 中的代码更改或 SQL Server 驱动程序更新。我不是 100% 确定是哪一个。

                                       
Improve this answer 改进此答案                                         
       
0
                   

Theme templates can be overridden with URL alias in the following way.可以通过以下方式使用 URL 别名覆盖主题模板。

  1. Add a preprocess function in theme template file在主题模板文件中添加预处理函数
  2. Get the URL alias, and choose the template file获取 URL 别名,然后选择模板文件

The full explanation with code is given in How to create a template for page created in drupal Admin with URL alias                            .完整的代码说明在如何为在drupal Admin中创建的带有URL别名的页面创建模板中给出。

                                       
Improve this answer 改进此答案                                         
       

Your Answer  您的答案 


                       

来自  https://drupal.stackexchange.com/questions/2345/how-do-i-use-url-aliases-in-menus