PHP includes menu - problems with sub-items

This is a discussion on "PHP includes menu - problems with sub-items" within the PHP Forum section. This forum, and the thread "PHP includes menu - problems with sub-items are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jan 16th, 2007, 21:22
Junior Member
Join Date: May 2006
Location: UK
Age: 35
Posts: 24
Thanks: 0
Thanked 1 Time in 1 Post
PHP includes menu - problems with sub-items

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jan 18th, 2007, 23:26
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP includes menu - problems with sub-items

Is the menu you want to 'include' fixed or does it change depending on content elsewhere?

If it's fixed, then you are going about this all the wrong way.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jan 19th, 2007, 16:17
Junior Member
Join Date: May 2006
Location: UK
Age: 35
Posts: 24
Thanks: 0
Thanked 1 Time in 1 Post
Re: PHP includes menu - problems with sub-items

No, it's fixed. It works fine without any sub-menus, but doesn't like the sub-menus at at. After I posted I had another look around google to see if I could find any other ways of doing it, and some seemed to be using an array, and some were using if/else, but that required an 'if' for each menu item, which I could imagine would become very tedious. All of them seemed to be way more complicated than what I've been using (and way beyond my PHP level). At the moment I've actually gone back to using the CSS method of adding an ID to the <body> and to each <a> link in the menu, which is a bit of a PITA because my memory's awful and I can see myself forgetting to add either the <body> or <a> id and wondering why the 'current' highlighting's not working.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jan 19th, 2007, 17:15
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP includes menu - problems with sub-items

In the css forum you will find a 'sticky' thread. In there is a link to a tutorial on css driven menu systems.

Work through that and you will be ok.

You can always come and ask about specifics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
include, php

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Menu problems CSS danny322 Web Page Design 1 Feb 22nd, 2008 19:49
Animation for menu items David Blake Flash & Multimedia Forum 12 Jun 14th, 2007 00:54
Problems with menu Francesca15 Web Page Design 2 May 10th, 2007 15:19
Menu problems in IE7 alsdevelopments Web Page Design 6 Apr 5th, 2007 15:57
html menu problems chobo Web Page Design 14 Mar 2nd, 2004 07:47


All times are GMT. The time now is 08:33.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42