Keywords in pages

3

How can I insert keywords and even the title of my page in these "Pages that do not exist".

For example, I made a pagination and my url changes as I change the value of url/conteúdo , the title and other keywords continue with the same page value main.

I use the header of my index.php for my other pages, such as conteudo.php , sobre.php etc ..

The title of my index.php is home , but the title of the conteudo.php file would have to be another, but the title is home as well.

Should I create headers for different files, or is there any way to change the title of the page without having to create another header?

  

There are a few methods to change the title via Javascript, but the ones I've always used have left the original title of the page in the head which is the right place and the title of the content in body in the middle of alum content. So I chose not to use it that way.

    
asked by anonymous 10.01.2018 / 12:23

2 answers

2

Here's a technique that might be interesting as well.

What you have to do is run the logic of the titles before html , see below.

<?php
//index.php
//aqui vem a lógica php antes do html carregar

$page = isset($_GET['menu'])?$_GET['menu']:'home';

switch($page){
    case 'home':
        $title = 'bem vindo ao site';
        $content = 'pages/home.php';
        break;
    case 'about':
        $title = 'nosso conteudo';
        $content = 'pages/about.php';
        break;
}
//agora vem o html como o echo no titulo
?>
<html>
<head>
    <title><?php echo $title;?></title>
</head>
<body>
<!-- conteúdo da paginação -->
<?php include $content;?>
</body>
</html>

But this technique is that if the site has many pages this logic may be unfeasible ...

    
10.01.2018 / 12:49
3

Young ah to solve your problem.

the page name is prog.php for example, first you get the name of the current page:

<?php
echo basename( __FILE__ ) ."\n";

$path_parts = pathinfo( __FILE__ );
 echo '1.'.$path_parts['dirname'], "\n";
 echo '2.'.$path_parts['basename'], "\n";
 echo '3.'.$path_parts['extension'], "\n";
 echo '4.'.$path_parts['filename'], "\n"; // desde o PHP 5.2.0
?>

This sequence will display:

prog.php
1./home/eq1okH
2.prog.php
3.php
4.prog

Now you need to assign the page name to a variable and always put it in your <title> tag:

$var_title = $path_parts['filename'];

<title><?php echo $var_title; ?>

Now whenever you change pages this variable will update and change the title and other things you want from your page.

    
10.01.2018 / 12:31