Click to See Complete Forum and Search --> : Automatically Updating Content (such as nav bars)
EpicKris
08-13-2008, 08:40 PM
I want to know the best way of going about inserting a menu bar from an external source into an html document. The purpose of this would be so that I would not have to constantly copy and paste the code into each page individually but simply update the 1 file to update all the pages automatically.
I don't want to use the template idea as I already have many templates planned and don't wish to be updating them either.
Thanks in advanced.
ryanbutler
08-14-2008, 09:27 AM
Use a server-side include for your navigation and simply include it the pages where you want to use it.
EpicKris
08-14-2008, 12:10 PM
Use a server-side include for your navigation and simply include it the pages where you want to use it.
I understand what you're saying, how would I go about accomplishing this? :confused:
ryanbutler
08-15-2008, 10:33 AM
Place only the navigation in a separate include file, such as PHP, asp, etc.
Then in the pages that you want to use the navigation, simply include it. In PHP:
<?php include('path/to/file.php');?>
ASP:
<!-- #include virtual="/missouricompact/functions.inc" -->
You might want to search Google if you need some basic information.
EpicKris
08-24-2008, 12:01 PM
I've used the php include code as suggested. But when viewing my site, none of it is displayed. Should I be using a php file instead of an html file for the main page (not the external sources which are already php).
ibechane
08-24-2008, 01:02 PM
if you have php script in a file, you have it name it with a .php file extension so the server knows to look for php code and deal with it.
EpicKris
08-24-2008, 01:12 PM
Oh. I did not realize this, thought it was more like inserting JavaScript into a file, as that still loads. Thanks guys!
EpicKris
08-24-2008, 02:13 PM
Unfortunately did not work, check my site www.wizardsdnd.com to see what is happening. :confused:
ibechane
08-24-2008, 02:15 PM
What does your php file look like?
EpicKris
08-24-2008, 02:22 PM
Main php file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Wizards D&D</title>
<link href="/css/default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<div id="header">
<?php include('/php/headers/default.php');?>
</div>
<div id="navbar">
</div>
<div id="content">
<h1>Welcome to Wizards D&D!</h1>
<p>You're not able to view any of Wizards D&D yet, but we assure you that we are working greatly on every aspect of it, our forum wont be immediately available at launch, however should only take a few days.</p>
<p>Because we feel that we should remain loyal to you as our community, we have provided you with our v3.5 resources available for download compatable with both Windows and Mac. </p>
<p>Character Sheets (<a href="archives/v35archive/Character%20Sheets.zip">zip</a>)<br />
Music (<a href="archives/v35archive/Music.zip">zip</a>)<br />
</p>
<p> </p>
<p>Anyone interested in working with Wizards D&D, particuly graphic design contact <a href="mailto:kristian.j.matthews@me.com">Kristian Matthews</a>.</p>
<p> </p>
<p>Regards,<br />
Kristian Matthews.<br />
Wizards D&D admin </p>
</div>
<div id="sidebar">
<?php include('/php/sidebars/default.php');?>
</div>
<div id="footer">
<?php include('/php/footer.php');?>
</div>
</div>
</body>
</html>
External php file (/php/footer.php):
<p>© iSphere</p>
ibechane
08-24-2008, 02:54 PM
For all of your includes, remove the first / in the file name, e.g. use "php/footer.php" instead of "/php/footer.php"
EpicKris
08-24-2008, 03:34 PM
Works fine, but say I had a subdirectory, would these links be site relative?
ibechane
08-24-2008, 03:59 PM
yeah they are relative to the file that calls the include. If you want to set the path, you can use set_include_path() http://us3.php.net/set_include_path
EpicKris
08-24-2008, 04:29 PM
I'm a little confused as to how I include a php file relative to the site (not the document with the include). :confused:
ibechane
08-24-2008, 05:39 PM
Like I said, if you want to set the include path, you use set_include_path(). You can set this to your base site directory and call this function at the beginning of each file that has includes. To find your base site directory's full path, make a php file in that directory with the following code:
<?php
echo getcwd(); //get current working directory
?>
This will give you a path to your base directory.
Then, copy that output and use this:
<?
set_include_path("your_getcwd_output");
?>
at the beginning of any page that has an include.
tizbo1423
08-29-2008, 10:57 AM
hi, sorry this doesn't have to do with your problem, but i have a question for you, if you dont mind.
i took a look at your site and was wondering how you got the bottom colored bar to stay at the bottom of each page. i was trying to have the same sort of thing through my page so i put it in my template, but it never stays at the bottom of the page itself. it floats right under where the table about it ends. is there a way to make it fixed to stay at the bottom of the page regardless of the table above it?