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

тэги:

Отправить новый комментарий

Содержимое этого поля хранится скрыто и не будет показываться публично.
  • Адреса страниц и электронной почты автоматически преобразовываются в ссылки.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Автоматический перевод строки.
  • Вы можете публиковать код, размещая его в <code>...</code> (generic) или в <?php ... ?> (раскрашенный PHP).

Дополнительная информация о настройках форматирования