Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JackT06

macrumors 6502
Original poster
Jul 24, 2009
293
0
Hello,

My problem is that for my menus i use the PHP include function, but i have just made a new directory to start making my blog inside, and my php include function isn't working, because my pages are in the previous directory, how can i get around it?

Below is my code:
HTML
Code:
<div id="menu">
<?php include("../Nav_Bar.php"); ?>
</div>
<!-- end #menu -->

PHP:
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<html>
<div id="menu">
<ul>
 
    <li><a href="index.html">Home</a></li>
    <li><a href="Blog.html">Blog</a></li>
    <li><a href="Gallery.html">Gallery</a></li>
    <li><a href="Documents.html">Documents</a></li>
    <li><a href="DoingDofE.html">Doing DofE</a></li>
    <li><a href="DofE_News.html">DofE News</a></li>
    <li><a href="ContactUs.html">Contact Us</a></li>
</ul>
</div>
 
If you are having problems with referencing the path to your include file you can do something like this.

PHP:
include ($_SERVER['DOCUMENT_ROOT'] . '/crg/admin_header.inc.php');

That way you are always starting from your root folder and then just tack on the path to your include file.
 
You could simply start all the address with a slash which sets it at the root directory. Instead of href="index.html" use href="/index.html" and no matter which directory you are in at the time it will bring you to the same address.
 
You could simply start all the address with a slash which sets it at the root directory. Instead of href="index.html" use href="/index.html" and no matter which directory you are in at the time it will bring you to the same address.

I'd agree with this. Simple and will work for all cases.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.