Want to use the main menu module with images?

If you have ever wanted to use images as menu items without hacking the main menu module this is for you. You can do this all in the template. First turn on output buffering, then send the buffer to a callback function which will find the menu links and swap them out for your image links.

Here are the steps. Open the index.php file for the template you want to use and right before the HTML tag put in the php function ob_start(“callback”) – callback being the name of the function you will use – and at the very end of the file put in ob_end_flush(). Now just include the callback function somewhere before you start the buffer and you’re done.

Here’s what the function does: First it will load info on every menu item. Then for each menu item it will check the parameters to see if a menu image has been assigned – in the administrator, choose to edit the menu item and under parameters assign an image from the images/stories directory. Usually if an image is assigned to that parameter it will show up to either the left or right of the link. This changes that. If an image is assigned the function will create the text link to search for and the new image link then it executes the swap. After it runs through every menu item it just returns the buffer which prints out to the browser. Pretty basic and you’ll probably have to do some tweaking to get it just right for yourself but it’s a nice way to use images without hacking any core files. Oh, and if you’re just looking to use non web safe fonts then couple this method with a text-to-image conversion script and dynamically generate images from the menu item name. You could also use this with content headings or module headings or just about anything. Have fun.

Here’s the callback function, put it above ob_start(): Download

Nonprofit news, strategy, and tactics sent straight to your inbox
Sign up for the Soapbox Engage newsletter

This entry was posted on Wednesday, September 27th, 2006 at 9:19 am and is filed under Joomla, PHP, quick tips, templates. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.