How to set active page class in a header included in all pages?

0

My site has a header that is called on all internal pages with the include function of php. It turns out that I would like to have class="active" on the page that is active. How do I do this if I only have one header for all internal pages? I am using bootstrap 3.

    
asked by anonymous 18.02.2014 / 00:18

1 answer

2

One approach would be to use the following on your pages:

$menuAtivo = 'identificador_menu_ativo'; // o identificador deve ser modificado de acordo com a página (inicio, cadastro, listagem por exemplo)
include 'cabecalho.php';

You can use the above code on all pages by entering a variable to identify the menu item before including the header. Inside the header.php, you can use something like:

<ul>
    <li <?php echo $menuAtivo == 'inicio' ? 'class="ativo"' : '' ?> > Início </li>
    <li <?php echo $menuAtivo == 'cadastro' ? 'class="ativo"' : '' ?> > Cadastro </li>
    <li <?php echo $menuAtivo == 'listagem' ? 'class="ativo"' : '' ?> > Listagem </li>
</ul>
    
18.02.2014 / 01:45