-1
Recently I learned how to leave a static site a little dynamic, putting the footer and header in 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
only has the page header, footer.php
only has the footer, and the index.php
only has the PHP command that is calling the file funcoes.php
(first script I pasted into question), header.php
and footer.php
.
And I have more documents called page_home.php
, page_ultimasnoticias.php
, page_contato.php
and page_privacidade
. Inside them only the content of the page, without footer and without header.
Yes, it is relevant, otherwise we will not have the slightest notion of what you have done and how to modify to meet your need.
– Woss
@Andersoncarloswoss I updated the question.
– jim
@Diogenessilva how is the page being loaded in the URL? Like this?
http://127.0.0.1/pagina.php
– Jorge.M
@Jorgematheus I’m using the Apache server. The URL looks like this: http://localhost/site/? p=home, http://localhost/site/? p=contact...etc
– jim
If you already have all this logic to change the title, what is the difficulty of doing exactly the same thing for the META?
$titulo="contato"; $keywords="formulário, fale conosco, SAC... $description="Uma linda e aconchegante página de contato, com todos os campos e botões que você espera"
– Bacco
@Bacco That’s not quite it, I don’t know put a single META Description and Keywords for each page, being that I only have 1 header for all.
– jim
If you change the title, you are changing the header. Just apply the same logic to the meta tags. (the title is part of the header).
– Bacco