You should find a way to pass the name of the post to your php script. You could even use the same attribute p
and change the current code, or use another attribute and pass the name of the post. I will show using the 2nd option.
First, set the new variable, I will use here in the example the variable post
via GET
. I also set the other variables here at the beginning of the script
$titulo = '';
$keywords = '';
$descricao = '';
$post = empty($_GET['post']) ? '' : $_GET['post'];
In this case, the decision code on the page that already exists should only rotate if the variable is not informed, or comes blank. In that case, you can put the whole switch
within a if
. Put a else
if you want to fill in the other variables.
if (empty($post)) {
// switch aqui
} else {
$titulo = 'Post';
}
And finally, at the hour of require_once
, see again if the $post
is empty, if you are doing what you already do 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, say to the post meuArquivo.php
as you put it in the picture, it would be like this:
<a href="index.php?post=meuArquivo">Meu Arquivo</a>
Now, the script with everything 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>
I don’t know if I understand, but putting require_once 'posts/page_' .... is not that?
– Luís Almeida
if that’s what you want to know, to access files inside directories, use
/
, for example,posts/meuprimeiropost.php
– Costamilam
I have to say, you’ve managed to summarize the problem in this picture much better than the other four or five times together. Now it will be possible to draw up a reply.
– Woss
Whew, at least now came a post that actually has something that opens file! The previous ones did not speak anything of require. See if next time you ask the question with all the details instead of creating 3289 accounts (and think it’s stalking). With details it is possible to help you. Without details, there is no willingness to guess what you want.
– Bacco
@Bacco I’m sorry, I’m new to PHP, so I didn’t know which codes were relevant to show, but I realized that in doubt it’s better to show everything related (no exaggeration).
– Sabrina marçã
Yes, and stop thinking we’re chasing you. Simply read what is asked in the comments and try to help us solve your problem. Creating accounts and accounts and reposting the same thing disturbs the whole site. Just edit the question as comments ask for your help, and create new question only after solving the previous step.
– Bacco