|
Posted by Els on March 16, 2007, 4:08 am
Please log in for more thread options
Toby A Inkster wrote:
> Els wrote:
>
>> <li><a <?php if ($_SERVER['PHP_SELF']=="/photography.html") {print
>> ('class="current"');}else{print ('href="/photography.html"');}
>> ?>>photography</a></li>
>
> Is this more readable?
>
> <?php
> $menus = array(
> 'a' => array(
> 'home' => '/index.html',
> 'sitemap' => '/sitemap.html',
> 'contact' => '/contact.html'
> ),
> 'b' => array(
> 'about' => '/about.html',
> 'blog' => 'http://blog.locusmeus.com/',
> 'photography' => '/photography.html',
> 'computer' => '/computer.html',
> 'travel' => '/travel.html',
> 'exit' => '/exit.html'
> )
> );
>
> print '<div id="nav">'."\n";
> foreach ($menus as $class => $menu)
> {
> printf('<ul class="%s">'."\n", $class);
> foreach ($menu as $label => $url)
> {
> $attr = sprintf('href="%s"', htmlentities($url));
> if ($_SERVER['PHP_SELF']==$n) $attr = 'class="current"';
>
> printf('<li><a %s>%s</a></li>'."\n",
> $attr, htmlentities($label));
> }
> print "</ul>\n";
> }
> print "</div>\n";
> ?>
Thanks! :-)
As you may have guessed, I don't know much PHP, so I just couldn't
have come up with this lot, and even when reading it, I don't
understand half of it.
However, I copied it into my file, above my own code, and it just
doesn't write the 'current' class.
(and while you're at it - could you make the href appear *plus* add a
class "partof" on pages that aren't in the menu, like on this one:
http://locusmeus.com/tent-city-london.html ?) ;-)
--
Els http://locusmeus.com/
|