You should figure out how to pass the post name to your php script. It could even use the same attribute p
and give a change in the current code, or use another attribute and pass the name of the post. I will show using the 2nd option.
First, define the new variable, I will use here in the example the variable post
via GET
. I also defined the other variables here at the beginning of the script
$titulo = '';
$keywords = '';
$descricao = '';
$post = empty($_GET['post']) ? '' : $_GET['post'];
In case, the decision code on the page that already exists should only run if the variable is not informed, or it is blank. In this case, you can put all switch
within if
. Put a else
if you want to populate the other variables.
if (empty($post)) {
// switch aqui
} else {
$titulo = 'Post';
}
And finally, at the time of require_once
, again see if $post
is empty, if it is do what it does today, otherwise call the file in /post
.
if (empty($post)) {
require_once 'page_' . $pagina . '.php';
} else {
require_once 'posts/' . $post . '.php';
}
To create the link within the pages, let's say for the meuArquivo.php
post as you put it in the image, it would look like this:
<a href="index.php?post=meuArquivo">Meu Arquivo</a>
Now, the script together would look like this:
<?php
$titulo = '';
$keywords = '';
$descricao = '';
$post = empty($_GET['post']) ? '' : $_GET['post'];
$pagina = empty($_GET['p']) ? 'home' : $_GET['p'];
if (empty($post)) {
switch ($pagina):
case 'contato':
$titulo = 'Contato ';
break;
case 'privacidade':
$titulo = 'Privacidade ';
break;
case 'ultimasnoticias':
$titulo = 'Ultimas Noticias';
break;
default:
$titulo = 'Home';
$pagina = 'home';
endswitch;
} else {
$titulo = 'Post';
}
?>
<html>
<head>
<title><?php echo $titulo; ?></title>
<meta name="keywords" content="<?php echo $keywords; ?>">
<meta name="description" content="<?php echo $descricao; ?>">
</head>
<body>
<?php
if (empty($post)) {
require_once 'page_' . $pagina . '.php';
} else {
require_once 'posts/' . $post . '.php';
}
?>
<footer>Rodapé</footer>
</body>
</html>