Title in friendly URL

Asked

Viewed 493 times

-2

Like I do to change the title of the sticky pages in the friendly URL?

below follows the friendly url script

<div id="conteudo">
   <?php
    $url = $_GET['url'];
    $quebraUrl = explode('/', $url);                
    $categoria = $quebraUrl[0];                 
    $paginas = array('home', 'empresa', 'servicos', 'produtos', 'noticias', 'dicas', 'fale-conosco');


    //HOME
    if(!isset($categoria) || $categoria == ''){
        include("paginas/home.php");
    }
    //PAGINAS FIXAS
    else if(isset($categoria) && in_array($categoria, $paginas)){
        include("paginas/".$categoria.".php");  
    }

  ?>                   
</div>

and below the menu.php

<div id="menu">
        <ul id="categoria">
            <a href="<?php echo URLBASE; ?>/home" title="#"><li>HOME</li></a>
            <a href="<?php echo URLBASE; ?>/cursos" title="#"><li>CURSOS</li></a>
            <a href="<?php echo URLBASE; ?>/video-aulas" title="#"><li>VÍDEO AULAS</li></a>
            <a href="<?php echo URLBASE; ?>/artigos" title="#"><li>ARTIGOS</li></a>
            <a href="<?php echo URLBASE; ?>/tutoriais" title="#"><li>TUTORIAIS</li></a>
            <a href="<?php echo URLBASE; ?>/dicas" title="#"><li>DICAS</li></a>
            <a href="<?php echo URLBASE; ?>/noticias" title="#"><li>NOTÍCIAS</li></a>
            <a href="<?php echo URLBASE; ?>/fale-conosco" title="#"><li>FALE CONOSCO</li></a>
        </ul>


    </div>

and below the header.php

<?php require_once("sistema/config.php"); require_once("sistema/funcoes.php"); error_reporting(0); ?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Project WEB - Códigos, Scripts, Dicas de Programação e muito mais!</title>
<link href="<?php echo URLBASE; ?>/css/style.css" rel="stylesheet" type="text/css">
</head>

<body>
<!-- CORPO -->
<div id="corpo">

    <!-- HEADER -->
    <div id="header">
        <!-- LOGO -->
        <div id="logo">
            <a href="<?php echo URLBASE; ?>/home" title=""><img src="<?php echo URLBASE; ?>/imagens/logo.png" alt="imagens/logo.png" title="Project WEB - Códigos, Scripts, Dicas de Programação e muito mais!"></a>
        </div>

        <!-- MENU -->
        <?php include_once("includes/menu.php"); ?> 
    </div>
  • Hello Hello, there is a horizontal menu and I am using url friendly, but the title of the pages does not exchange, I would like you to exchange

  • 1

    The title is defined within the tag title in the head. You know how to do that?

  • sincerely not Would you help me please

  • Okay, better. One more question: You’re opening different pages and files, right? When you use this: <a href="<?php echo URLBASE; ?>/home" title="#"><li>HOME</li></a> so you don’t pass any GET or POST parameters... this is just the code you have? you have a PHP file for each page?

  • That’s all I have: a header.php menu.php and content.php

  • Hi charlie, I wish that by clicking on a certain page you change the title, the way this title does not change, the page changes and the title remains the same could help me

  • 1

    You need to set a variable to use it within the title tag.

  • don’t know how, could help me charlie I’m not very good at php I’m learning

  • 1

    Okay, why don’t you use the friendly url template I went through instead of what you use? Create a var $teste ="meu titulo"; and in the title use <title><php? echo $teste; ?></title>

  • what model charlie ? I’m not seeing

  • I believe that the set of classes here http://github.com/szagot/config will help you to work separation, in particular the class Uri (http://github.com/szagot/config#Uri).

Show 6 more comments

1 answer

1

Well as I understand it, this is only a matter of logic.

In your file, config.php I believe that it is in it that you are rescuing the url, you could create a variable to contain the title.

<?php
$titulo = 'Titulo Padrao';

if($url == 'home')
   $titulo = 'Inicio';
else if($url == 'cursos')
   $titulo = 'Cursos';
?>

In the archive header.php where the tag is located you would print the variable value.

<title><?php echo $titulo; ?></title>

It’s a quick suggestion for your problem, but I advise you to work smarter, separating the "HTML" view from php codes.

Find out more about Classes like Smarty that can facilitate your life in the matter of code structuring and tals.

  • 1

    The Twig seems much more modern.

  • 1

    I’ll take a look at it in brasofilo ;)

Browser other questions tagged

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