I'm using
PHP to include my menu for a site (which is a styled <ul>), and to highlight the current site. It's working well, except that for menu items which have sub categories, there's no closing </li> on the menu item, so if it's one of those pages, it's not getting highlighted (I'm adding in a "current" id using the
php). I've tried making it an if/else statement, but that's not working either. Obviously I've got the syntax wrong somewhere, but I can't figure out where (I'm pretty new to
PHP). Any advise appreciated.
HTML
- Code: Select all
<!-- NAVIGATION -->
<div class="navigation">
<div class="curved_corner"></div>
<p class="navtitle">What's here?</p>
<!-- start navigation include -->
<?php include("includes/menu_include.php"); ?>
<!-- end navigation include -->
CSS
- Code: Select all
.navlist { width: 199px; color: #467aa7; background-color: #F2F3F5; border-right: 1px solid #c8c8c8; border-bottom: 1px solid #c8c8c8; font: 12px verdana,sans-serif; }
.navlist li { list-style: none; }
.navlist a { color: #467aa7; text-decoration: none; display: block; border-left: 1em solid #c8c8c8; border-top: 1px solid #c8c8c8; padding: 4px 8px; }
.navlist a:hover { border-color: #606B8B; }
ul.navlist li#current a { border-color: #606B8B; }
.subnavlist li a { border: 0; border-left: 0.8em solid #c8c8c8; padding: 3px 4px; margin-left: 20px; }
Menu include
HTML (menu.
html)
- Code: Select all
<ul class="navlist">
<li><a href="index.php">Home</a></li>
<li><a href="designs.php">Designs</a>
<ul class="subnavlist">
<li><a href="design1.php">Design 1</a></li>
<li><a href="design2.php">Design 2</a></li>
<li><a href="design3.php">Design 3</a></li>
</ul>
</li>
<li><a href="graphics.php">Graphics</a></li>
<li><a href="about.php">About</a></li>
<li><a href="links.php">Links</a></li>
<li><a href="contact.php">Contact Me</a></li>
And finally, the include that I'm having problems with:
- Code: Select all
<?php
$submeunuitem = ("<li><a href=\"" . basename($_SERVER['PHP_SELF']) . "\">(.*)</[^>]+></a>|U");
if ( $submenuitem == "|<li><a href=\"" . basename($_SERVER['PHP_SELF']) . "\">(.*)</[^>]+></a>|U" ) {
$menusub = file_get_contents("menu.html");
$menusub = preg_replace("|<li><a href=\"" . basename($_SERVER['PHP_SELF']) . "\">(.*)</[^>]+>|U", "<li id=\"current\"><a href=\"" . basename($_SERVER['PHP_SELF']) . "\">$1</a>", $menu);
echo $menusub;
} else {
$menu = file_get_contents("menu.html");
$menu = preg_replace("|<li><a href=\"" . basename($_SERVER['PHP_SELF']) . "\">(.*)</[^>]+></li>|U", "<li id=\"current\"><a href=\"" . basename($_SERVER['PHP_SELF']) . "\">$1</a></li>", $menu);
echo $menu;
}
?>
Am I trying to go about it the right why using an if/else, or is it simply that I've got the syntax wrong?