Images instead of text link in (sub)menu

Feed 1 posts, 2 voices

Avatar
11 posts

HI, I need some help with a menu. I want to show images in the menu.

I have found this snippet but I have a hell to make it work togheter :)

check the fourth post by David
This is how I want it to work

Thx!

 
Avatar
16 posts

Here is the snippet posted by David

<a class=“menuh” href=”<?php echo URL_PUBLIC; ?>”>
<img border=“0” src=”<?php echo URL_PUBLIC; ?>public/images/home.png” alt=“home” class=“menup” />
</a>
<?php foreach($this->find(’/’)->children() as $menu): ?>
<a class=“menuh” href=”<?php echo $menu->url(); ?>”>
<img border=“0” src=”<?php echo URL_PUBLIC; ?>public/images/<?php echo $menu->slug(); ?>.png” alt=”<?php echo $menu->title(); ?>” class=“menup” />
</a>
<?php echo “\n”; ?>
<?php endforeach; ?>

Here’s what it means.

The first line is a link to the home page because the “<?php echo URL_PUBLIC; ?>” as the global variable that contains the URL of your Frog installation.

I guess the next lines are what you don’t understand.
The “foreach” loops all the pages that are contained below the Home Page hierarchy.

So for example let’s say you have this hierarchy :

The “foreach” will create a menu item for the 3 items “Characteristics, Plans Unites & Prices and Neighborhood”

So for each item it will set the href=”“ to the item url automatically with $menu->url()
Then set the source of the image to its slug with $menu->slug(). I’m guessing this is the part you don’t get. Think of the slug as the page name. When you enter a page title, the slug is automatically generated.
For example, let’s say you create a page with the title “My first webpage”.
If you click on the “metadata” tab, you will find the slug “my-first-webpage”.
So the images of the menu will be name like the slug. So in the example I posted earlier, the first image would be characteristics.png for the page with the Title Characteristics, the next image would be plans-units-prices (look at the metadata tab to get the slug).

Finally the foreach will add the page title as the alternative (alt) text to the image.

Hope it’s clear now.
Steven