This can’t be done with php. You can do it with javascript, though. That is, all the contents on a single page, and each link makes some content disappear and others appear:
For this example I will use jQuery
$('[data-pagina]').on('click', function(){
var pagina = $(this).data('pagina');
$('.pagina').hide();
$(pagina).show();
});
.pagina {
display:none;
}
.pagina#homepage {
display:block; /* aparecer esta por default, no carregamento da página
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav>
<ul>
<li data-pagina="#homepage">homepage</li>
<li data-pagina="#contactos">contactos</li>
<li data-pagina="#produtos">produtos</li>
</ul>
</nav>
<div class="pagina" id="contactos">
<h2>conteudos dos contactos</h2>
</div>
<div class="pagina" id="homepage">
<h2>conteudos dos homepage</h2>
</div>
<div class="pagina" id="produtos">
<h2>conteudos dos produtos</h2>
</div>
Complete code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
ul {
text-align: right;
}
li {
list-style:none;
display:inline-block;
margin: 0 10px;
}
.pagina {
display:none;
}
.pagina#homepage {
display:block; /* aparecer esta por default, no carregamento da página*/
}
</style>
<title>Tudo numa só página</title>
</head>
<body>
<nav>
<ul>
<li data-pagina="#homepage">homepage</li>
<li data-pagina="#contactos">contactos</li>
<li data-pagina="#produtos">produtos</li>
</ul>
</nav>
<div class="pagina" id="contactos">
<h2>conteudos dos contactos</h2>
</div>
<div class="pagina" id="homepage">
<h2>conteudos dos homepage</h2>
</div>
<div class="pagina" id="produtos">
<h2>conteudos dos produtos</h2>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$('[data-pagina]').on('click', function(){
var pagina = $(this).data('pagina');
$('.pagina').hide();
$(pagina).show();
});
</script>
</body>
</html>
Hello John, welcome to Sopt, already have some code made ? If yes, you can post here for a better help on your problem?
– FábioArsénio
Index.php <!DOCTYPE html> <html> <head> <title>Site - Homepage</title> </head> <body background= "image.jpg"> <font align= center face= "Comic Sans MS" size=-1 Color= ##000000> <H1>Welcome to the site</H1> <font align= left face= "Comic Sans MS" size=-1 Color= #000000> <H2>Highlights:</H2> <p>bla bla in discount</p>
– João Santos
João, you can post the code of your index.php ?
– FábioArsénio
You want to redirect to another page when you click a button for example?
– FábioArsénio
Then I have 2 more.php files that I want to join
– João Santos
Yes for example, Fábio. But the content of the other files must be all in index.php
– João Santos
Then, you can simply join the contents of the other PHP files into the same code where you have the index or you can choose to go to another page by clicking a button
– FábioArsénio
yes ok Fábio and then as I do?
– João Santos
I want to merge all the files in the index, but I still want to be able to navigate the site as if it were in different files.
– João Santos
It’s called a parameter and I must wear the href
– João Santos
I think it is better for example you have the index, and then for example a tab or some button to navigate to another page, I think it will be more practical and ergonomic
– FábioArsénio
Yes it was the easiest but the exercise is to have everything together in the same file and even use can navigate as if the files were separate
– João Santos