After some frantic hair-pulling, I finally got this to work in Drupal 6.x. Here I am presenting 2 ways to add images/Html to Drupal node titles (both based on template.php), and you can choose any of them as per your needs. There are pretty other options (including doing this via background-images & css).
- Add these 2 methods to your theme’s template.php:
{syntaxhighlighter brush: php;fontsize: 100; first-line: 1; }function themename_menu_item_link($link) {
if (empty($link[‘localized_options’])) {
$link[‘localized_options’] = array();
}if(strpos($link[‘title’], ‘<img’) !== false) {
// Allow HTML if the menu description is an image tag:
$link[‘localized_options’][‘html’] = true;
}return l($link[‘title’], $link[‘href’], $link[‘localized_options’]);
}function phptemplate_get_primary_links() {
return menu_tree(variable_get(‘menu_primary_links_source’, ‘primary-links’));
}{/syntaxhighlighter}Then in page.tpl.php, write this wherever you want to print your primary menu:<?php print phptemplate_get_primary_links(); ?>
You should off-course change the menu names for your desired menu. You would nead to repeat the _get_menu_name() method for each menu you want to support.
- Add this single method to your theme’s template.php:
{syntaxhighlighter brush: php;fontsize: 100; first-line: 1; }function themename_get_primary_links($links) {
foreach ($links as &$link) {
if(strpos($link[‘title’], ‘<img’) !== false) {
// Allow HTML if the menu description is an image tag:
$link[‘html’] = true;
}
}return($links);
}{/syntaxhighlighter}
Then in page.tpl.php, write this wherever you want to print your primary menu:<?php print theme('links', themename_get_primary_links($primary_links), array('class' => 'links primary-links')) ?>
You should again change the menu names for your desired menu.
There could be many more variations of these 2 approaches depending upon how you want the menu items to appear, in a list, independently, or whatever.
Too Good Tutorial…. It’s really more helpful to me……
Second one have worked nicely……
Thanks a lot to give this guide……
Awesome tutorial, worked well for me too. Thanks a lot.
Same here, indeed. Many thanks!
Hey – I am certainly happy to discove this. Good job!
Awesome job there, as you mentioned it can be done via CC and background image, but your methode is a dynamic one, everytime I need to change that image, I do not need to go and edit my code, I can do it via admin panel in the description section.