0
votes

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.

2

2 Answers

0
votes

First, your theme_links implementation should not include theme in its function name. And second to quote the documentation page linked before, `$variables['links'] is …

An associative array of links to be themed. The key for each link is used as its CSS class. Each link should be itself an array, with the following elements

Your replacement does not work because you're using strpos on an array.

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:

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.

0
votes

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). You don't have to change anything else besides YOURTHEMENAME to your theme's name:

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'];
    }
}