Jump to content

How to create a Template?


MasterACE14

Recommended Posts

I want to create a template for my website, but I don't want to include, header, left nav, bottom, right nav, etc etc on every single new page I make, is their a way to include all them on 1 page, and just call it template.php but make it so that I can display all the other pages content in the center of the page, without using frames. A template similar to PHP-Nuke, has left nav, header, right nav, bottom, and the content in the center, how can I go about doing this?

 

Regards ACE

Link to comment
Share on other sites

No problem:

build your template and place this code (with minor mods) where you want your page content to be.

<?PHP
	switch ($_GET['page]) {
		default:
		case "page1":
			require_once ("lib/page1.php");
			break;
		case "page2":
			require_once ("lib/page2.php");
			break;
		case "page3":
			require_once ("lib/page3.php");
			break;
		case "page4":
			require_once ("lib/page4.php");
			break;
	}// end switch
?>

Now make a folder called 'lib' and place your content pages in there. Set your links on your template like this:

<a href="template.php?page=page1">HOME PAGE</a>

 

If you want search engine friendly url's, you'll have to do a mod_rewrite.

Link to comment
Share on other sites

ok, I got that working, But my template is a little whacked  :-\

 

I'm new to CSS and I've made a template, but I've made separate PHP pages for each section of the template, footer, header, leftnav, rightnav etc.

 

for each PHP page, I have linked them to the CSS file that does the whole page layout, but i'm guessing that I should just make separate CSS files for each section. here is my current CSS file that I have linked in every PHP file.

 

/* set margins, padding, and inline-level alignment */
body,div { color: white; margin: 0; padding: 0; text-align: center }

/* set widths and float nav & ads div content boxes */
#nav	{ float: left; width: 100px	}
#ads	{ float: right; width: 100px }

/* set side txt margins 5px > nav & ads widths */
#txt	{ margin-left: 105px; margin-right: 105px }

/* ensure footer stays at the bottom */
#ftr	{ clear: both }

/* show boundaries and set image sizes - for clarity */
#hdr, #ftr	{ background: red				}
#nav, #ads 	{ background: yellow			} 
#txt		{ background: green				}

#hdr img		{ width: 250px; height: 25px	}
#ads img		{ width: 75px; height: 100px	}
#txt img		{ width: 150px; height: 200px	}

 

heres the index.php page:

 

<html>
<head>
<link rel = "stylesheet" title = "CF Layout" type = "text/css" href = "css/page-layout.css" >
<?php

// Include's
include('variables.php');

?>
<title><?=$gamename?> - Online MMORPG</title>
</head>
<body>
<?php
include('head.php');
?>
<?php
include('leftnav.php');
?>
<?php
include('rightnav.php');
?>
<div id = "txt">
<center>
<?php
	switch ($_GET['page']) {
		default:
		case "home":
			require_once ("lib/home.php");
			break;
		case "page2":
			require_once ("lib/page2.php");
			break;
		case "page3":
			require_once ("lib/page3.php");
			break;
		case "page4":
			require_once ("lib/page4.php");
			break;
	}// end switch
?>
</center>
</div>
<?php
include('footer.php');
?>
</body>
</html>

 

I get everything showing up where it should, but the page is black and white, and the text is the same color as the background of the appropriate section.

 

any ideas?

 

Regards ACE

Link to comment
Share on other sites

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.