繁体   English   中英

Drupal更改菜单网址

[英]Drupal Change Menu url

使用Drupal 7,我有一个具有多个字段的内容类型。 然后,我有一个查看页面,它采用了这种内容类型并显示了所有内容。

因此,可以将其想象为博客。然后是博客的主要显示页面。

我进行了设置,以便在适当的位置自动创建菜单项。

我还设置了Pathauto,以便它创建链接www.site.com/blog_anchor_node-title

单个内容页面将永远不会被访问,因此我不必担心奇怪的URL,但是,由于pathauto不支持井号,因此我使用了

我需要通过template.php文件用#替换锚的每个实例。

这将允许锚标记自动添加到我自己的主菜单,页脚以及“博客”页面上的跳转菜单中。

到目前为止,我拥有的最接近的东西是:

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

这行不通。

首先,您的theme_links 实现不应在其函数名称中包含主题 其次引用引用之前链接的文档页面,`$ variables ['links']是…

要主题化的链接的关联数组。 每个链接的键都用作其CSS类。 每个链接本身应该是一个数组,包含以下元素

您的替换无效,因为您在数组上使用了strpos

要使此工作转到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.
  }
  //...
}

还要确保该函数的名称正确。

为了让我在URL中使用#符号,对我有用的是在我的template.php文件中添加了以下内容(在要调用的函数上方)。 您无需将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