Recently I learned how to make a static site a bit dynamic by putting the footer and header into a single document for all pages. But for each page I need a different meta description and meta keywords. How do I do this?
The script I used:
<?php
function carrega_pagina(){
(isset($_GET['p'])) ? $pagina = $_GET['p'] : $pagina = 'home';
if(file_exists('page_'.$pagina.'.php')):
require_once('page_'.$pagina.'.php');
else:
require_once('page_home.php');
endif;
}
function gera_titulos(){
(isset($_GET['p'])) ? $pagina = $_GET['p'] : $pagina = 'home';
switch ($pagina):
case 'contato':
$titulo = 'Contato - BizarroNEWS';
break;
case 'privacidade':
$titulo = 'Privacidade | BizarroNEWS';
break;
case 'ultimasnoticias':
$titulo = 'Últimas Notícias | BizarroNEWS';
break;
default:
$titulo = 'BizarroNEWS | Home';
break;
endswitch;
return $titulo;
}
Document index.php:
<?php
require_once('funcoes.php');
require_once('header.php');
carrega_pagina();
require_once('footer.php');
?>
I have 3 documents called header.php
, index.php
and footer.php
.
The header.php
has only the header of the page, footer.php
only has the footer, and the index.php
only has the PHP command that is calling the file funcoes.php
(first script that I pasted in the question) header.php
and footer.php
.
And I have more documents called page_home.php
, page_ultimasnoticias.php
, page_contato.php
and page_privacidade
. Within them only the content of the page, without footer and without header.