Jump to content
jcc5018

Php Navigation

Recommended Posts

hey guys, I recently managed to just about figure out the CSS based navigation system for my site, though its not quite done. But now I need to figure out how to link it to the pages. My idea was that instead of having each link set using a regular href set, Each link would instead be defining a variable. For example the home link would be defined something like <?php $page="home/main.htm"; ?> while another link could be <?php $page="home/history.htm"; ?>Then on the page that this navigation is on, it would include the various files with a statement such as <?php include($page); ?>That's the idea, to create a frame like site without frames, but of course nothing is ever that simple and I am again having trouble with making this work. The navigation is set up with a list and formatted with CSS, This is part of the code that I've played with so far. I'm going show each of the different way's I've tried writing this, neither way worked though.

<li class="Main"><a class="MenuBarItemSubmenu" href="#">Home</a>      <ul class="newbar">        <li><a  href="<?php $page="home/main.htm"; ?>">Main</a></li>        <li><a <?php $page='href="home/news.htm" '; ?> >News</a></li>        <li><a >History</a><?php $page="home/history.htm";?></li>      </ul>  </li>

Basically I think the links need to function more as buttons in a form that would display a different file depending on the one pressed. I'm choosing to do this, this way because I feel it would allow the navigation to register the active link when pressed. If I did it where I just included the navigation file in each set, I feel it would just constantly reset the nav and it wouldnt display the active link. But If you know a way to make that work with php, I can do that way instead, though it would be nice if my first idea actually worked for once.I am also going to need the site to display the active URL. I guess my first method may be harder to accomplish this so I dont know.

Share this post


Link to post
Share on other sites

nevermind I figured it out.This is what I did for anyone else who may want it.Each link gets written to post a variable for example:<a href="?page=main">The red changes depending on the link.Then I created a separate file to create switch statements. You have to use the GET statement first to pull the variable from the URL. Then for each case, it includes the actual link to the file I want loaded.

<?php$page=$_GET['page'];switch ($page){case "main":include "home/main.htm";break;case "history":include "home/history.htm";break;case "news":include "home/news.htm";break;case "books":include "bio/books.htm";break;case "edu":include "bio/edu.htm";break;case "exp":include "bio/exp.htm";break;case "goals":include "bio/goals.htm";break;case "personal":include "bio/personal.htm";break;case "skills":include "bio/skills.htm";break;case "strength":include "bio/strength.htm";break;case "work":include "bio/work.htm";break;case "basic":include "resume/basic.htm";break;case "complete":include "resume/complete.htm";break;case "skill":include "resume/skill.htm";break;case "standard":include "resume/standard.htm";break;default:include "home/main.htm";break;}

From this all I had to do is include an include (switch.php); statement in the main folder and so far it seems to be working just fine. Just keep in mind, any links within your site that you want to load on the same main template will not have the standard link format, it will instead have to be similar to the first line of code I posted above. and you will have to add the actual link in the switch file. Hope this helps others. I know it works in FF, not sure bout other browsers.

Share this post


Link to post
Share on other sites

That would be called a Modular page design.One index page, adding the 'called' page into a 'module' for the content. Include the header and footer, some sidebars as required, and 'done'.Nice work.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...