Jump to content

Question on PHP dynamic navigation (no database used)


Professor_Ape

Recommended Posts

I'm new here, learning php and have a question. I have dug through a couple searches but haven't found an exact solution to my problem.

 

On my site I am using a template system that works with a $page variable (e.g. ?page=home). The problem I'm having with this is that when you visit the gallery page, it loads a completely different page instead of using the root template. So far, I haven't figured out how to grab the content of the gallery and insert that into the root template while still showing the change in the site url.

 

So far what I'm using is this:

<div id="BWindow">
<div id="BHeader">
<img src="header.gif" height="" width="" alt="arlof creative services" title="arlof creative services">
</div>
<div class="Sidebar">
	<?php @ include ("menu.php"); ?>
</div>
<div class="Main">
	<?php
	$page = trim(addslashes($_GET['page']));
	if(!$page)
		$page = "home";
	if(!file_exists($page.".html"))
		include("error.html");
	else
		include($page.".html");
	?>
</div>
<?php @ include ("footer.php"); ?>
</div>

</body>

[sidenote]

I borrowed this code from an tutorial but I know what most of it does except the "!" in the if statements. Wasn't sure what to look up in the php manual (bang symbol? exclamation mark?) [/end sidenote]

 

This works fine except that I have a gallery in a directory "/s2/" off the root. Right now, in that folder I have to use an index.php in order to view this page. What I would like to do is show the change in the url "example.com/s2" but not leave the root template page by loading the gallery content into the template. Is this possible?

 

Regarding my nav, I'm using absolute urls for the Home and Gallery link because when you are on the gallery page and click the gallery link again, you end up with a url of "example.com/s2/s2/". Below is my nav code:

<ul class="MainNav">
<li><a href="http://example.com">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="http://example.com/s2/">Gallery</a></li>
<li><a href="<?php echo "?page=services"; ?>">Services</a></li>
<li><a href="<?php echo "?page=guarantee"; ?>">Guarantee</a></li>
<li><a href="<?php echo "./blog/"; ?>">Blog</a></li>
<li><a href="<?php echo "?page=freebies"; ?>">Free Stuff</a></li>
<li><a href="<?php echo "?page=contact"; ?>">Contact</a></li>
<li class="clientLogin"><a href="<?php echo "#"; ?>">Client Login</a></li>
</ul>

 

If this code is bad, please go easy, I'm still learning what php functions do and how to use them. If there are big security issues with this, please let me know while keeping the explanation understandable for a newcomer.

 

Thanks for looking over my code. I can use all the help I can get.

Link to comment
Share on other sites

Just found this in another post here which fixed my navigation probelms by explaining the difference between:

 

href=foo/bar.php

href=/foo/bar.php

href=bar.php

 

http://www.phpfreaks.com/forums/index.php/topic,111099.0.html

 

I knew how the "/" worked when navigation a hard drive but not on a web server. great information! seems basic but it's probably overlooked by many new web developers.

Link to comment
Share on other sites

No, not completely. I have the navigation thing solved but I still would like to know if it's possible to load the contents of the gallery into the root template file. The trouble I'm having with it is it utilizes sajax so there is php, javascript and html in the document and it also uses parts of the index template html. here is the script's site of origin:

 

http://www.ibm.com/developerworks/xml/library/os-php-rad1/

 

I guess I could put chunks of it in variables but that seems clumsy. I could use any help or insight on this issue. Please try to simplify any explanations because I am still learning about php's functions and what they do so I may not know what a function does if just code is posted without any explanation.

 

Thank you!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.