Answers:
在Drupal 6中,您不能在主题内使用挂钩或更改挂钩,因此您需要创建一个自定义模块来修改链接。完成后,您将想要实现hook_link()
(如果要创建新链接)或hook_link_alter()
(如果要修改现有链接)。
添加新链接:
example_link($type, $object, $teaser = FALSE) {
$links = array();
// Add a custom link to nodes
if ($type == 'node') {
$links['example_mylink'] = array(
'title' => t('Test link'),
'href' => 'foo',
'attributes' => array(
'title' => 'Test link',
),
);
}
return $links;
}
修改现有链接:
example_link_alter(&$links, $node, $comment = NULL) {
// Remove the read more link
unset($links['node']['node_read_more']);
// Change the title of the read more link
$links['node']['node_read_more']['title'] = t('More information');
// Move read more link to first slot
$link_read_more = $links['node']['node_read_more'];
unset($links['node']['node_read_more']);
$links = $links['node'];
$links['node'] = array(
'node_read_more' => $link_read_more,
) + $links;
// Move link to the last slot
$link_read_more = $links['node']['node_read_more'];
unset($links['node']['node_read_more']);
$links['node']['node_read_more'] = $link_read_more;
}
在Drupal 7中,这有点简单,因为主题可以实现alter hook。您正在寻找的alter hook是hook_node_view_alter()
:
function example_node_view_alter(&$build) {
// Remove the read more link
unset($build['links']['node']['#links']['node-readmore']);
// Add your own custom link
$build['links']['node']['#links']['example-mylink'] = array(
'title' => t('Test link'),
'href' => 'foo',
'html' => TRUE,
'attributes' => array(
'title' => 'Test link',
),
);
// Move read more link to first slot
$link_read_more = $build['links']['node']['#links']['node_read_more'];
unset($build['links']['node']['#links']['node_read_more']);
$links = $build['links']['node']['#links'];
$build['links']['node']['#links'] = array(
'node_read_more' => $link_read_more,
) + $links;
// Move link to the last slot
$link_read_more = $build['links']['node']['#links']['node_read_more'];
unset($build['links']['node']['#links']['node_read_more']);
$build['links']['node']['#links']['node_read_more'] = $link_read_more;
}
您可以将其直接放在template.php
文件中。