Keywords in Paginations

Asked

Viewed 37 times

3

How can I insert the Keywords and even the title of my page on those "Pages that don’t exist".

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

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

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

Should I create headers for different files or is there a way to change the page title without creating another header ?

There are some methods to change the title via Javascript, but the ones I used always left the page’s original title on 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.

2 answers

3

ah young to solve your problem.

the page name is Prog.php for example, first you take 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
?>

is 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 in your tag <title>:

$var_title = $path_parts['filename'];

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

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

2


Here’s a technique that might be interesting too.

What you have to do is execute titles logic 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...

  • Good! I learned this technique in the internship I was doing, it is very common and useful

  • @Juliohenrique97 I don’t work much with PHP, but for larger projects it may not be the best option, so your podelo can be more interesting. But for small projects this logic works well. What’s missing is an A/B SEO test to see which Google ranks best...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.