Submitted by Nik on
<?php
function mymodule_link_alter(&$node, &$links) {
foreach ($links as $module => $link) { // iterate over the $links array
//drupal_set_message(print_r($links)); // uncomment to display your $links array
// check if this element is the forward module's link
if ($module == 'forward_links') {
$title = t('Email this page to a friend'); // change the title to suit
$path = path_to_theme() . '/images/email.png'; // make an image path
// now update the links array
// set the title to some html of the image and choice of link text
$links[$module]['title'] = theme('image', $path, $title, $title) . ' Email';
// let's set some attributes on the link
$links[$module]['attributes'] = array(
'title' => $title,
'class' => 'forward-page',
'rel' => 'nofollow',
);
// this must be set, so that l() interprets the image tag correctly
$links[$module]['html'] = TRUE;
}
}
}
?>
<?php
function _phptemplate_variables($hook, $vars = array()) {
switch ($hook) {
case 'node':
foreach ($vars['node']->links as $module => $link) {
if ($module == 'forward_links') {
$title = t('Email this page to a friend');
$path = path_to_theme() . '/images/email.png';
$vars['node']->links[$module]['title'] =
theme('image', $path, $title, $title) . ' Email';
$vars['node']->links[$module]['attributes'] =
array('title' => $title, 'class' => 'forward-page', 'rel' => 'nofollow');
$vars['node']->links[$module]['html'] = TRUE;
}
}
$vars['links'] = theme('links', $vars['node']->links,
array('class' => 'links inline'));
break;
}
}
?>
Comments
Drupal Theme Garden replied on Permalink
Nice piece of code.
And, yes, you're right, template.php is better place.
Nik replied on Permalink
lgm replied on Permalink
Nik replied on Permalink
Joao replied on Permalink
As the print module maintainer, I would like to point out that there's better solutions in the case of the print module than either of the above. You can theme the $links link of the print module to your heart's content using the theme_print_format_link() function.
See more about that in #4 of http://drupal.org/node/190173.
Nik replied on Permalink
krunar replied on Permalink
hi,
is it possible to do this without making a module? somewhere in phptemplate for example.
Nik replied on Permalink
feelexit replied on Permalink
hi, I want to theme $links in comments
in _phptemplate_variables function, I add following code
case 'comment':
print_r($vars['comment']->links);
break;
nothing shows up, probably theres no such variable called $vars['comment']->links.
can you please show me how theme it in comment. I got stuck here for 2 days.
thank you so much for ur help.
vsotto replied on Permalink
does this work in drupal 6?
Nik replied on Permalink
Anonymous replied on Permalink
For D6 you should probably use YOURTHEME_preprocess_node instead of _phptemplate_variables though.
Anonymous replied on Permalink
Thanks for this article, it worked for me
Mould Maker replied on Permalink
It is easy to do it for my website, but I found that if I use _preprocess_node(&$vars, $hook) then I can not get the node ID in the function.
Add new comment