I've been trying to figure this one out for awhile, but since i can't find the solution im hoping someone could help me with this.
I made a website, in which there are at the moment 3 different menu options, home contact and an orderpage. Which are in different subfolders. I have index.php in the main folder, and from there on i have a folder named includes and layout. In includes i have the contact.php, orderpage.php. And in layout i have the .css and the menu.php for example.
Now i need to use the include 'something.php'; to include all the pages i need. So you don't get redirected to another page it will just include a different page each time you click another option in the menu.
i hope my question is clear, if not please tell me what i should include.
From the question it Reads like that: You try to load all Pages at Once and then simply switch between them.
Problem: PHP doesnt work Like that. Dynamic Content on already loaded Pages can only be handled with Javascript. PHP is only run Server side and all the Code has already run, after you enter a Page.
What you indeed can do, is loading all Content at once in seperate Div Containers and then simply Switching them by Hiding showing them. But you realy should do a Seperate Page for each of your Pages. So onclick you Switch to the correct Page. If you load a PHP Page, you only use the Code you want for this Page. Dont worry about loading Template Files like css or Images new. On the first Access to a Webpage, the User downloads all Files, if they dont Change, he has them already.
If I understood you correctly. You want to load 3 pages into the content block of your layout without redirecting to a new page. You can't use php for this as what you want is client side.
Add jQuery library
Use the following as an example of your menu. data-page
should contain the actual filename you want to include:
HTML:
<a href="javascript:;" class="page" data-page="home">Home</a>
<a href="javascript:;" class="page" data-page="contact">Contact</a>
<a href="javascript:;" class="page" data-page="order">Order</a>
In your HTML, have a div with ID for where you want the contents to load
<div id="contents"></div>
Add script to load page into div
<script>
$(".page").click(function(){
$("#contents").load("includes/"+$(this).data("page")+".php");
});
</script>
Sorry it's untested as I typed it on the fly so if there's an error please let me know. You'd obviously need to learn more about jquery if the above is unclear but this is the way I'd do it (not that it's the best way to show pages)
trigger
to achieve this.