Web Design Forums

PHP

Have questions about PHP? Ask them here and our experts will assist you before you know it! You can also find help in the documentation at PHP.net.

Creating a static page template



Site of the Month Nominations
ENTER YOUR SITE NOW!

Reply
 
LinkBack Thread Tools
Old January 10 '10, 11:07 PM (#1)
poker158149 is offline
WDF Member
 
poker158149's Avatar
 
Join Date: September 2009
Posts: 22
poker158149 is an unknown quantity at this point
Creating a static page template

Hi everyone.

I was wondering, how can one create a page in PHP that can be used as a template for the entire site?

I.E.
When I wanna make a change to the copyright or the navigation on each one of the pages on my site, I don't want to have to go to each individual page to do so.
I want to be able to change one thing on the index.php and it changes on each page.

Like, I see some sites that do this:
site.com/index.php
site.com/index.php?page=about
site.com/index.php?page=contact
etc.

Is this the type of thing I'm looking for? And if so, how can it be done?

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 10 '10, 11:41 PM (#2)
Unknown98 is offline
WDF Member
 
Unknown98's Avatar
 
Join Date: May 2008
Location: Houston
Posts: 38
Unknown98 is an unknown quantity at this point
The sites that do site.com/index.php?page=about get their content from a database. This allows more room on the server for actual files, so instead of creating a file for each page, they input the content on that page into a MySQL database and then use the site.com/index.php?page=about method. This is useful if you have tons of pages or content.

To do what you're wanting to do, you need to create a php file with the code in it you want (for example footer or navigation). Then in every page you want that file to appear, use the php include function to include that php file. For example:

I create a footer.php file with the copyright info, styling, etc. Then in index.php, about.php, and contact.php at the bottom of the page I put this line: <? include("footer.php"); ?>

That will display the code of footer.php in every page that you put the above line of code. Then if you want to edit your footer, you just have to edit footer.php and it will update on all pages.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 11 '10, 12:25 AM (#3)
poker158149 is offline
WDF Member
 
poker158149's Avatar
 
Join Date: September 2009
Posts: 22
poker158149 is an unknown quantity at this point
Wow, thank you very much.

Now, can I do the <? include("footer.php"); ?> on pages that use MySQL databases type pages or not?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 11 '10, 05:44 PM (#4)
Unknown98 is offline
WDF Member
 
Unknown98's Avatar
 
Join Date: May 2008
Location: Houston
Posts: 38
Unknown98 is an unknown quantity at this point
Yes. Those pages just store the code in a database table instead of a file. It's the exact same code, just in a different format. You could copy/paste code from a php file into a database and it would work using the ?page=about format. Lots of Content Management systems use this method, the most noticable is PHP Fusion. It stores all your custom pages in the database, then displays each page using www.site.com/viewpage.php?page_id=X format. You can potentially have hundreds of pages stored in the database, but only use one file (viewpage.php) to view them. That's what makes php awesome
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 11 '10, 06:39 PM (#5)
poker158149 is offline
WDF Member
 
poker158149's Avatar
 
Join Date: September 2009
Posts: 22
poker158149 is an unknown quantity at this point
Haha that's awesome.
I'm really going to have to learn how to create a site like that.
And one more question. Or, clearing up.
The <? include("footer.php"); ?> code: does this go inside or outside the <html> tags on the php page?
And what exactly do I put in "footer.php"? Like, do I start it with some php code? Do I have to include <html> tags again? How to I set it up?

Thanks for your help so far!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 11 '10, 06:54 PM (#6)
Unknown98 is offline
WDF Member
 
Unknown98's Avatar
 
Join Date: May 2008
Location: Houston
Posts: 38
Unknown98 is an unknown quantity at this point
PHP code can go anywhere in the page most of the time, I usually put mine in the <body> section. But for things like restricted access pages for registered users only, you should put the restrict code at the very top, even before your <html> tag. On my site I'm including the footer. The footer file can either be a complete html file or just a div, it works either way. Here's my footer.php:

Code:
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
A.footer:link {
text-decoration:none;
color:#14A1FF;
font-size:1.1em;}
A.footer:visited {
text-decoration:none;
color:#14A1FF;}
A.footer:active {
text-decoration:none;
color:#14A1FF;}
A.footer:hover {
text-decoration:none;
color:#75C7FF;}
</style>
</head>
<body>
<div>
<center><a class="footer" href="about.php">about</a> | <a class="footer" href="faq.php">faq</a> | 
<a class="footer" href="/help">help</a></center>
</div>
</body>
</html>
Now I did it that way because I needed a stylesheet for my footer, and I didn't know if the stylesheet would work if it wasn't in the <head> portion and I didn't have time to experiment . But you could just have a file with <div id="footer">copyright &copy; 2010</div> in it, include it, and it would display that line of code.

I set up a test website that used the ?page=page format a while before, letmme see if I can find it... If I can I'll post the code.

Last edited by Unknown98; January 11 '10 at 06:55 PM. Reason: Spelling... ugh
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 11 '10, 07:24 PM (#7)
poker158149 is offline
WDF Member
 
poker158149's Avatar
 
Join Date: September 2009
Posts: 22
poker158149 is an unknown quantity at this point
Thank you so much for all of your help.
And if you do find that code, I'd be even more appreciative :P
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 13 '10, 04:42 PM (#8)
Unknown98 is offline
WDF Member
 
Unknown98's Avatar
 
Join Date: May 2008
Location: Houston
Posts: 38
Unknown98 is an unknown quantity at this point
I think I deleted or overwrited it, sorry. I did find a tutorial on creating these kinds of pages though that may help you. You should be able to skip the steps where you install apache, mysql and php on your server, your host should already have these installed (You couldn't really create a website without them).

http://www.codewalkers.com/c/a/Datab...h-PHP-MySQL/1/

If that doesn't help much (I didn't really read through all of it), I may be able to write something up to show you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 13 '10, 06:54 PM (#9)
poker158149 is offline
WDF Member
 
poker158149's Avatar
 
Join Date: September 2009
Posts: 22
poker158149 is an unknown quantity at this point
That's alright. Thanks so much for the link, I'll definitely look into it.
Thanks for your time!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 16 '10, 12:28 PM (#10)
Unknown98 is offline
WDF Member
 
Unknown98's Avatar
 
Join Date: May 2008
Location: Houston
Posts: 38
Unknown98 is an unknown quantity at this point
Erm, kinda off-topic me thinkies.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old January 23 '10, 11:30 PM (#11)
Unknown98 is offline
WDF Member
 
Unknown98's Avatar
 
Join Date: May 2008
Location: Houston
Posts: 38
Unknown98 is an unknown quantity at this point
Hey, I found those codes if you still want them. First block is just the css stuff. Second block is the first page (say index.php). Third block is the second page (say test.php). Ask me if anything's not working. And of course you can fetch the id number on the second block from a database, you don't have to manually name it id=1.

Code:
.container {
    border: 1px solid black;
    width: 80%;
    background-color: #FBFBFB;
    padding: 5px;
    margin: 0 auto;
}
.footer {
    width: 100%;
    background-color: #E8F4F9;
    text-align: center;
}


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="default.css" /
</head>
<body>

<div class="container">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod 
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu 
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in 
culpa qui officia deserunt mollit anim id est laborum.</p>

<a href="test.php?id=1">Test</a>

<div class="footer">
<p>Copyright &copy; 2009. All Rights Reserved.</p>
</div>

</div>

</body>
</html>


Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="default.css" /
</head>
<body>

<div class="container">

<?php
echo $_GET['id'];
?>

<div class="footer">
<p>Copyright &copy; 2009. All Rights Reserved.</p>
</div>

</div>

</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Web Design Forums » Programming Help » PHP

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple way to get a dynamic php page to autogenerate a static html one? Umfanekiso PHP 6 August 30 '08 08:44 PM
Need Help Creating a name and image upload page buckaholic2000 General Web Design Discussion 3 August 7 '08 11:05 PM
Page Error loading --- Memory issue? Janice HTML and CSS Help 3 February 27 '07 01:31 AM
Using Variables From Include Page. kleptos PHP 8 April 22 '03 04:30 PM

 
User Infomation
Your Avatar

Site Of The Month

Ticket Cake
Ticket Cake

Ticket Cake is a drupal based event ticketing platform. It features that ability to browse events and share them.

Nominate Your Site Now!

Advertisement
WolfCMS.org

Latest Articles
- by RickM
- by bfsog

Advertisement

Partner Links



All times are GMT -4. The time now is 02:50 AM.


WebDesignForums.net is Copyright © 2010 RikeMedia.

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163