简体   繁体   English

Drupal更改菜单网址

[英]Drupal Change Menu url

With Drupal 7, I have a content type with multiple fields. 使用Drupal 7,我有一个具有多个字段的内容类型。 I then have a view page that takes this content type and displays all the content on it. 然后,我有一个查看页面,它采用了这种内容类型并显示了所有内容。

So think of it like a blog.. and then a main blog display page. 因此,可以将其想象为博客。然后是博客的主要显示页面。

I have it set so that a menu item is automatically created in the proper place. 我进行了设置,以便在适当的位置自动创建菜单项。

I also have Pathauto set up so that it creates a link www.site.com/blog_anchor_node-title 我还设置了Pathauto,以便它创建链接www.site.com/blog_anchor_node-title

The individual content page will never be accessed, so I'm not worried about the strange url, however, since hashtags are not supported by pathauto, I used anchor 单个内容页面将永远不会被访问,因此我不必担心奇怪的URL,但是,由于pathauto不支持井号,因此我使用了

I need every instance of anchor to be replaced with a # via the template.php file. 我需要通过template.php文件用#替换锚的每个实例。

This will allow anchor tags to automatically be added to my main menu, the footer, as well as jump menus on the "blog" page it's self. 这将允许锚标记自动添加到我自己的主菜单,页脚以及“博客”页面上的跳转菜单中。

so far, the closest thing I have is: 到目前为止,我拥有的最接近的东西是:

    function bartik_theme_links($variables) {  
    $links = $variables['links'];
    if (!(strpos($links, "_anchor_") === false)) {  
        $links = str_replace("http://", '', $links);
        $links = str_replace("_anchor_","#",$links);
   } }  

This doesn't work. 这行不通。

First, your theme_links implementation should not include theme in its function name. 首先,您的theme_links 实现不应在其函数名称中包含主题 And second to quote the documentation page linked before, `$variables['links'] is … 其次引用引用之前链接的文档页面,`$ variables ['links']是…

An associative array of links to be themed. 要主题化的链接的关联数组。 The key for each link is used as its CSS class. 每个链接的键都用作其CSS类。 Each link should be itself an array, with the following elements 每个链接本身应该是一个数组,包含以下元素

Your replacement does not work because you're using strpos on an array. 您的替换无效,因为您在数组上使用了strpos

To make this work go to the API documentation page , copy the code (yes the hole code) and just insert something like the following at the beginning: 要使此工作转到API文档页面 ,请复制代码(是孔代码),然后仅在开头插入以下内容:

function bartik_links($variables) {
  $links = $variables['links'];
  foreach($links as $key => $l) {
    // do your replacements here.
    // You may want to print out $l here to make sure
    // what you need to replace.
  }
  //...
}

Also make sure the function is named properly. 还要确保该函数的名称正确。

To allow me to use the # symbol in a URL, what worked for me was adding the following to my template.php file (before the function above you want to call). 为了让我在URL中使用#符号,对我有用的是在我的template.php文件中添加了以下内容(在要调用的函数上方)。 You don't have to change anything else besides YOURTHEMENAME to your theme's name: 您无需将YOURTHEMENAME之外的其他任何内容更改为主题的名称:

function YOURTHEMENAME_url_outbound_alter(&$path, &$options, $original_path) {
    $alias = drupal_get_path_alias($original_path);
    $url = parse_url($alias);

    if (isset($url['fragment'])){
        //set path without the fragment
        $path = $url['path'];

        //prevent URL from re-aliasing
        $options['alias'] = TRUE;

        //set fragment
        $options['fragment'] = $url['fragment'];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM