0

With Drupal 7, I have a content type with multiple fields. 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

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

I need every instance of anchor to be replaced with a # via the template.php file.

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.

4

2 回答 2

0

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

要主题的链接的关联数组。每个链接的键都用作其 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.
  }
  //...
}

还要确保函数名称正确。

于 2013-06-24T07:25:24.957 回答
0

为了允许我在 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'];
    }
}
于 2014-10-23T20:26:22.063 回答