Gmo
Gmo

Reputation: 13

php website one page for design

I'm done creating a php website that has 6 pages, and the structure of the pages is the same for each one of them, the only thing that changes is the content, so is the same header, same design and same footer, the only thing that changes like I said before is the content itself.

so i was thinking instead of having many pages, I could have only one design page, and change only the content, what do you recommend?,and how do I do that?, also im not planning installing anything like Typo3, wordpress, joomla or whatever in my server, so I want something i could do using php idk. thank you!

Upvotes: 1

Views: 1246

Answers (3)

Luke
Luke

Reputation: 1870

Simplest solution is to create separate files.

  • header.php
  • footer.php
  • menu.php

In header.php put your code from header

<?php ?>
<HTML>
<HEAD>
</HEAD>
<BODY>
...
<? ?>

Same goes for footer and menu files.

Then you can use it by including them.

Your index.php could look like following.

<?php 
include("header.php");
include("menu.php");
?>

<h1> This is my content </h1>

<?php
include("footer.php");
?>

This is the easiest option I think for someone who doesn't want to spend using templates, CMS etc. Also you can create function called header that takes $title and changes title of your window. Up to you.

Upvotes: 3

user622378
user622378

Reputation: 2346

Simple and easy solution:

create footer.php and header.php

and in the header.php you can have something like this:

<?php function top_header($title) { ?>
    <html>
    <head>
    <title> <?php echo $title ?> </title>
    </head>
    <body>
<?php } ?>

footer.php

<?php function footer() { ?>
    </body>
    </html>
<?php } ?>

Your index.php could look this:

<?php
include("header.php");
include("footer.php");
top_header("Title of the page");
?>
Hello World!
<?php footer(); ?>

Upvotes: 0

Dan
Dan

Reputation: 2195

Sounds like you want AJAX. Use prototype. You can make one page, and then use prototype to swap out the content (which could include a PHP page) based on user clicks.

Upvotes: 0

Related Questions