Jump to content

Recommended Posts

I had a similar problem the other day. PHP does not have a "start at the root of the site" directive like HTML does.

 

Basically what you are going to have to do is use something like this on each page, changing each one to fit where the include file is in relation to the file your including into

 

include('menu.php');

 

include('../menu.php');

 

include('folder1/menu.php');

 

../ takes you back 1 folder level

 

Hope this helps, if not, then post back with your directory structure and I can help more there

 

Nate

include('../menu.php');

 

can i do this if my menu.php is in root folder and i want to use it in folder1 directory?

 

 

httpdocs:/includes/menu.php here i have th file

 

 

httpdocs:/coverstory/index.php in this index.php im including menu.php. Currently I have menu.php also in coverstory folder so its working.

 

If your wanting to simply get your menu on all pages so you don't have to edit it all the time try something like this. Use a standard header / footer template. I am using a table based layout in this example

 

main.php

<html>
<head>
<title></title>
</head>
<body>
<table width="75%" height="500" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="75" colspan="2" align="center">Banner Goes Here </td>
  </tr>
  <tr>
    <td width="200" align="center">Menu Goes Here </td>
    <td>
All content loads here

<?php function footer(){ ?>
 </td>
  </tr>
  <tr>
    <td height="15" colspan="2" align="center">Footer Goes Here </td>
  </tr>
</table>
</body>

<? } ?>

 

The rest of your pages only need to look like this

 

<?php include('main.php') ?>

This content here will always load in the cell marked content

<?php footer(); ?>

 

I find this method much easier to work with.

 

 

But onto your question.

 

yes, if your directory structure is something like this

 

/root

| folder1

    |--index.php

|folder2

    |-- index.php

index.php

menu.php

 

Then to include the menu inside folder 1 or 2, you use

include('../menu.php');

 

 

at the root index.php you use

include('menu.php');

 

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.