Posted by abrabapupa on June 15, 2009 at 10:12pm
Hello there,
i found that it's nearly impossible to alter the 'read more' link (line when displaying node teaser).
I want to simply replace it with nice image and title, instead of a textual link.
I tried to implement following functions in my template.php file:
mythemename_link(..) - never called
mythemename_link_alter() - same
the only hook which is available is
mythemename_links()
but altering a link in this function is a bit awkward
function mythemename_links($links, $attributes = array('class' => 'links')) {
if (isset($links['node_read_more']))
{
$links['node_read_more'] = ....
}
return theme_links($links, $attributes);
}is there a more elegant way?
Comments
what about the read more link
what about the read more link are you trying to change?
-Corey
- Corey
http://www.thefreecollege.com
...
Yes, there is a much more elegant way, Image Replacement - http://adaptivethemes.com/use-icons-for-node-and-comment-links
IR preserves the text for accessibility and SEO and is a lightweight CSS only solution, no PHP required.
Note that my sites site_name also uses an image replacement technique.
Responsive Drupal Themes | Drupal 8 Design Initiative | Certified to Rock
CSS-only text replacement is not always an option
When you need to display icons inline, a CSS text replacement is not quite appropriate solution. Not saying, that this solution fits only for simplest forms - replacing a link text with image. What if i want to display an icon + text? Or make some links to open in a new page etc.
So, i asking second time: is there a more elegant way to modify a way how links markup generated by theme?
If you are wanting to replace
If you are wanting to replace the text completely, you can always try the String Overrides module.
-Corey
- Corey
http://www.thefreecollege.com
...
icon + text = background image + padding.
open in new window is a link attribute or js behaviour, nothing to do with what you asked originally.
"a CSS text replacement is not quite appropriate solution", yeah, whatever man, you stick to that ok.
/dev/null
Responsive Drupal Themes | Drupal 8 Design Initiative | Certified to Rock
...
sure thing, but i cannot predict what customer/designer might want to put there next time. This is why i want a most generic solution. And what is you proposed is very limited one.
P.S. I really wonder, why do i need to use CSS hacks, when i have a direct access to all sources and can modify markup in any way i want it to be.
ed_readmore module
Have you tried using http://drupal.org/project/ed_readmore module yet?
tcvn
Where I work http://www.ichanoi.com/
Just what i looking
Thanks for pointer!
This is yet another thing which i wanted to fix among other things related to 'read more' link itself.
The problem that I see with
The problem that I see with the http://drupal.org/project/ed_readmore module is that I could not alter the link from the node links section.
For solving the problem I have made a custom module and use the link_alter hook:
function customhooks_link_alter(&$links, $node) {
// Remove the link from the node's $links output if the option is enabled
unset($links['node_read_more']);
$links['node_read_more'] = array(
'title' => "Read the rest of <b>$node->title</b>",
'href' => "node/$node->nid",
'attributes' => array('title' => t('Read the rest of !title.', array('!title' => $node->title)), 'rel' => 'nofollow'),
'html' => true
);
}