gotmedia Posted July 30, 2008 Share Posted July 30, 2008 I know it's possible, I'm just not sure how. I have a sidebar, and in certain sections, the sidebar menu changes. I want to say "when you are in THIS section, show THIS menu" (in the sidebar). How would I go about doing that? Quote Link to comment Share on other sites More sharing options...
revraz Posted July 30, 2008 Share Posted July 30, 2008 Use IF statements and check the current page you are on and decide what you want to show for that page. Quote Link to comment Share on other sites More sharing options...
gotmedia Posted July 31, 2008 Author Share Posted July 31, 2008 Okay cool! Would this work: <?php if ($dir == "media") { echo '<div class="menu"> <ul> <li> <a href="/media/">media</a> </li> <li> <a href="/media2/">media 2</a> </li> <li> <a href="/media3/">media 3</a> </li> </ul> </div>' } else if ($dir == "about") { echo '<div class="menu"> <ul> <li> <a href="/about/">about</a> </li> <li> <a href="/about2/">about 2</a> </li> <li> <a href="/about3/">about 3</a> </li> </ul> </div>' } else if ($dir == "extras") { echo '<div class="menu"> <ul> <li> <a href="/extras/">extras</a> </li> <li> <a href="/extras/">extras</a> </li> <li> <a href="/extras/">extras</a> </li> </ul> </div>' } ?> I think it's pretty close? Quote Link to comment Share on other sites More sharing options...
ikmyer Posted July 31, 2008 Share Posted July 31, 2008 use the var: $_SERVER['SCRIPT_FILENAME'] http://us3.php.net/manual/en/reserved.variables.server.php Quote Link to comment Share on other sites More sharing options...
gotmedia Posted July 31, 2008 Author Share Posted July 31, 2008 Oh okay, then this right? <?php if ($_SERVER['media']) { echo '<div class="menu"> <ul> <li> <a href="/media/">media</a> </li> <li> <a href="/media2/">media 2</a> </li> <li> <a href="/media3/">media 3</a> </li> </ul> </div>' } else if ($_SERVER['about']) { echo '<div class="menu"> <ul> <li> <a href="/about/">about</a> </li> <li> <a href="/about2/">about 2</a> </li> <li> <a href="/about3/">about 3</a> </li> </ul> </div>' } else if ($_SERVER['extras']) { echo '<div class="menu"> <ul> <li> <a href="/extras/">extras</a> </li> <li> <a href="/extras/">extras</a> </li> <li> <a href="/extras/">extras</a> </li> </ul> </div>' } ?> As read in the link you gave me, it would be ($_SERVER['/public_html/extras/']) since they want the absolute pathname, correct? Quote Link to comment Share on other sites More sharing options...
ikmyer Posted August 1, 2008 Share Posted August 1, 2008 sorry, you'll want something like this... you'll have to base the menu of the current file name or something... which $_SERVER['SCRIPT_FILENAME'] will tell you... <?php $current_page = basename($_SERVER['SCRIPT_FILENAME']); if ($current_page == 'media.php') { echo '<div class="menu"> <ul> <li> <a href="/media/">media</a> </li> <li> <a href="/media2/">media 2</a> </li> <li> <a href="/media3/">media 3</a> </li> </ul> </div>'; } else if ($current_page == 'about.php') { echo '<div class="menu"> <ul> <li> <a href="/about/">about</a> </li> <li> <a href="/about2/">about 2</a> </li> <li> <a href="/about3/">about 3</a> </li> </ul> </div>'; } else if ($current_page == 'extras.php') { echo '<div class="menu"> <ul> <li> <a href="/extras/">extras</a> </li> <li> <a href="/extras/">extras</a> </li> <li> <a href="/extras/">extras</a> </li> </ul> </div>'; } ?> ... should work. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.