Need help, how would you do this? (Can't think of title)
10 replies, posted
I don't know how to explain this very well, but what I want to do is to like have 1 html file or something and when I edit it, other pages on my website will automatically update too?
For an example, say I have 5 html pages. Each have a sidebar "news". When you want to add news to your website, you'd need to edit each file.
How would you do this? I'm sure I can adapt it to my website.
Solution 1: Use a database.
Solution 2: Include the sidebar with php's include() function
Solution 3: Update each one manually
First is preferred.
I can make a database, but how would I configure it
Using a database really adds a whole level of different requirements - administration access, management tools, yadda yadda yadda. So it's important to ask yourself - are you going to be adding news frequently?
It's not news, but like if I want to change something in my navigation bar I'd have to edit each page file.
Then the way to go is with PHP's [URL="http://php.net/manual/en/function.include.php"]include[/URL] function.
It's very simple - imagine your main file is something like:
[code]
<html>
<head>
<title>My super cool page!!!</title>
</head>
<body>
<div id="content">
Welcome to my page!!!
<img src="dancingbaby.gif" /><img src="dancingbaby.gif" />
<img src="skullz.gif" />
<marquee>Welcome freind!!</marquee>
</div>
</body>
</html>
[/code]Now, you want your navigation to go above the content, you simply do something like this:
[code]
<html>
<head>
<title>My super cool page!!!</title>
</head>
<body>
<?php include('navigation.html'); ?>
<div id="content">
Welcome to my page!!!
<img src="dancingbaby.gif" /><img src="dancingbaby.gif" />
<img src="skullz.gif" />
<marquee>Welcome freind!!</marquee>
</div>
</body>
</html> [/code]Where [b]'navigation.html'[/b] is a path to the file containing the markup for your navigation. Read the documentaton for [b]include[/b] that I posted above (or [b] [URL="http://php.net/manual/en/function.include.php"]here[/URL] [/b]), and don't be afraid to ask if you need more help.
Thank you Joe, but I can't seem to get it working. I am attempting to use this for a news sidebar for testing purposes.
Here is what my sidebar things says on the main page:[code]
<div class="right" id="sidebar_outer">
<div id="sidebar">
<?php include('sidebaritems.html'); ?>
</div>
</div>
[/code]
And this the sidebaritems.html:[code]
<div class="box">
<div class="box_title">News</div>
<div class="box_content">
<p>Testing Phase</p>
</div>
</div>
[/code]
The news box doesn't show up. These files are in the same directory too.
And for my navigation bar, when you are at a page it highlights the tab you're on. How would I incorporate the include function to something like that?
[QUOTE=alphaspida;26692885]Thank you Joe, but I can't seem to get it working. I am attempting to use this for a news sidebar for testing purposes.
Here is what my sidebar things says on the main page:[code]
<div class="right" id="sidebar_outer">
<div id="sidebar">
<?php include('sidebaritems.html'); ?>
</div>
</div>
[/code]
And this the sidebaritems.html:[code]
<div class="box">
<div class="box_title">News</div>
<div class="box_content">
<p>Testing Phase</p>
</div>
</div>
[/code]
The news box doesn't show up. These files are in the same directory too.
And for my navigation bar, when you are at a page it highlights the tab you're on. How would I incorporate the include function to something like that?[/QUOTE]
Where your code uses;
[code]<div class="right" id="sidebar_outer">
<div id="sidebar">
<?php include('sidebaritems.html'); ?>
</div>
</div>[/code]
It is a php file, right? Just checking as you said earlier you were using all html.
It's called index.html
[QUOTE=alphaspida;26699152]It's called index.html[/QUOTE]
It must have a .php extension, and it must be running under a server with PHP. Are you doing that? (If not, don't be scared, it's really really easy - are you running Windows?)
[QUOTE=StinkyJoe;26699615]It must have a .php extension, and it must be running under a server with PHP. Are you doing that? (If not, don't be scared, it's really really easy - are you running Windows?)[/QUOTE]
Oh wait, the index file has to have the php extension?
And I'm using Lithium Hosting ;p.
[editline]14th December 2010[/editline]
Thanks, it works.
Do you know how to do the navigation bar?
Sorry, you need to Log In to post a reply to this thread.