Reply to comment

Drupal 6. Alter links

Julia 16/01/2010

How to remove unnecessary links from the group of links under node.

There are two methods for altering links, one at theme layer and the other hrough a custom module.

Use hook_link_alter() in a module

<?php

function mymodule_link_alter(&$links, $node) {
  foreach (
$links as $module => $link) {
    if (
strstr($module, 'blog')) {
      unset(
$links[$module]);
    }
  }
}

?>

At theme layer

In the template.php file:
change or create the new function phptemplate_preprocess_node(&$vars)

<?php
function phptemplate_preprocess_node(&$vars) {  

// unset from links forward link
  
foreach ($vars['node']->links as $module => $link) {
        if (
$module == 'forward_links') {
          unset(
$vars['node']->links[$module]);
        }
      }
  
$vars['links'] = theme('links', $vars['node']->links, array('class' => 'links inline'));
}
?>

In this example I removed all links conneted with 'forward' module

тэги:

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options