holmedwa04 Posted August 24, 2009 Share Posted August 24, 2009 Hey EveryoneI have a website and it currently uses PHP includes so that the header, footer, navigation and right pane can be edited and shown on any page. This makes life somewhat easier. But I was wondering if it was possible to get it to only display the pages you were not on...so it looks at the page you are on and then removes that from the navigation include? So if there were 4 pages... page one would have 2,3,4 page two 1,3,4 page three 1,2,4 page four 1,2,3.Any help would be greatly appreciated. Thanks in advance.N.B. I am a complete novice with PHP and have only used include functions so far! Link to comment Share on other sites More sharing options...
Synook Posted August 24, 2009 Share Posted August 24, 2009 You could just check what page you are on (I suppose it's stored in the querystring) and not display that one.Do you have any code you could show us? Link to comment Share on other sites More sharing options...
dsonesuk Posted August 24, 2009 Share Posted August 24, 2009 depending on how the menu is produced, but you could assign a specific class or id to each button fro example:<div class="Button but1"><a href="#">Home</a></div><div class="Button but2"><a href="#">Abouts Us</a></div><div class="Button but3"><a href="#">Hobbies</a></div><div class="Button but4"><a href="#">Other</a></div>then use css in that page to hide <style type="text/css">.but2 {display:none;}</style> Link to comment Share on other sites More sharing options...
holmedwa04 Posted August 24, 2009 Author Share Posted August 24, 2009 This is the code that is in the navigation include file... <ul id="nav"><li>Navigation</ul><ul id="menu"><li><a class="nav" href="index.php">Home</a><li><a class="nav" href="lights.php">How to Make Lights</a><li><a class="nav" href="archive.php">News Archive</a><li><a class="nav" href="about.php">About the Layout</a><li><a class="nav" href="layout.php">Track Plan</a><li><a class="nav" href="news.php">Layout News</a></ul> Link to comment Share on other sites More sharing options...
dsonesuk Posted August 24, 2009 Share Posted August 24, 2009 you have no closing </li> tags ? anyway assign specific id or class to li tags<ul id="nav"><li>Navigation</li></ul><ul id="menu"><li class="but1"><a class="nav" href="index.php">Home</a></li><li class="but2"><a class="nav" href="lights.php">How to Make Lights</a></li><li class="but3"><a class="nav" href="archive.php">News Archive</a></li><li class="but4"><a class="nav" href="about.php">About the Layout</a></li><li class="but5"><a class="nav" href="layout.php">Track Plan</a></li><li class="but6"><a class="nav" href="news.php">Layout News</a></li></ul>insert css into page which one you wish to hide. Link to comment Share on other sites More sharing options...
holmedwa04 Posted August 24, 2009 Author Share Posted August 24, 2009 Thanks for your reply... but that means I need to add a piece of CSS to every page... I was hoping there might be some PHP around that would find out the page you were on and then hide it maybe? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 24, 2009 Share Posted August 24, 2009 You can get the filename of the current page like this: $fname = basename($_SERVER['SCRIPT_NAME']); You can compare that before you print each menu item. <?php if ($fname != 'index.php') { ?><li><a class="nav" href="index.php">Home</a></li><?php } ?> or <?php if ($fname != 'index.php') echo '<li><a class="nav" href="index.php">Home</a></li>'; ?> Link to comment Share on other sites More sharing options...
holmedwa04 Posted August 24, 2009 Author Share Posted August 24, 2009 Thanks justsomeguy.... I have tried it with this code: <ul id="nav"><li>Navigation</ul><ul id="menu"><?php if ($fname != 'index.php') echo '<li><a class="nav" href="index.php">Home</a></li>'; ?><?php if ($fname != 'lights.php') echo '<li><a class="nav" href="lights.php">How to Make Lights</a></li>'; ?><?php if ($fname != 'archive.php') echo '<li><a class="nav" href="archive.php">News Archive</a></li>'; ?><?php if ($fname != 'about.php') echo '<li><a class="nav" href="about.php">About the Layout</a></li>'; ?><?php if ($fname != 'layout.php') echo '<li><a class="nav" href="layout.php">Track Plan</a></li>'; ?><?php if ($fname != 'news.php') echo '<li><a class="nav" href="news.php">Layout News</a></li>'; ?></ul> But with no luck... is there something that I am missing? Link to comment Share on other sites More sharing options...
dsonesuk Posted August 24, 2009 Share Posted August 24, 2009 try using an array and do a compare of links<?php $fname = basename($_SERVER['SCRIPT_NAME']);$nav= array();$nav[0]=array("index.php","Home");$nav[1]=array("lights.php","How to Make Lights");$nav[2]=array("archive.php","News Archive");$nav[3]=array("about.php","About the Layout");$nav[4]=array("layout.php","Track Plan");$nav[5]=array("news.php","Layout News");echo ("<ul id=\"nav\">");echo ("<li>Navigation</li>");echo ("</ul>");echo ("<ul id=\"menu\">");for ($i=0;$i<count($nav);$i++){if($fname != $nav[$i][0]){echo("<li><a class=\"nav\" href=\"".$nav[$i][0]."\">".$nav[$i][1]."</a></li>");}}echo ("</ul>");?>Sorry realised you did not need styling with this method Link to comment Share on other sites More sharing options...
justsomeguy Posted August 24, 2009 Share Posted August 24, 2009 But with no luck... is there something that I am missing?The definition of $fname. Link to comment Share on other sites More sharing options...
holmedwa04 Posted August 24, 2009 Author Share Posted August 24, 2009 When I put this code in: $fname = basename($_SERVER['SCRIPT_NAME']); It just shows up where ever I place it and doesn't actually do anything. Please could someone write out the code that I need? I have very little experience of PHP and so struggle to know where anything goes. Sorry to be so much bother. Link to comment Share on other sites More sharing options...
dsonesuk Posted August 24, 2009 Share Posted August 24, 2009 on the page you want to insert the nav llink you include ref to the nav pageanypage.php<?phpinclude("nav.php");?>and insert the function to retrieve nav links within the body<?phpshownav();?>nav.php insert this into a completly blank page<?phpfunction shownav(){$fname = basename($_SERVER['SCRIPT_NAME']);$nav= array();$nav[0]=array("index.php","Home");$nav[1]=array("lights.php","How to Make Lights");$nav[2]=array("archive.php","News Archive");$nav[3]=array("about.php","About the Layout");$nav[4]=array("layout.php","Track Plan");$nav[5]=array("news.php","Layout News");echo ("<ul id=\"nav\">");echo ("<li>Navigation</li>");echo ("</ul>");echo ("<ul id=\"menu\">");for ($i=0;$i<count($nav);$i++){if($fname != $nav[$i][0]){echo("<li><a class=\"nav\" href=\"".$nav[$i][0]."\">".$nav[$i][1]."</a></li>");}}echo ("</ul>");}?>and thats it Link to comment Share on other sites More sharing options...
holmedwa04 Posted August 24, 2009 Author Share Posted August 24, 2009 Ok thanks, I have done all but the second step about "insert the function to retrieve nav links within the body" where do I place this code? Along with the include function? On every page? Link to comment Share on other sites More sharing options...
dsonesuk Posted August 24, 2009 Share Posted August 24, 2009 good place to place the <?php include("nav.php"); ?> is in the head between <head> and </head>you place <?php shownav(); ?> where you want the nav links to appear, usually within a div container, but depends how you have designed the page so i'm just guessing here. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.