0
I have a menu in html :
        <ul>
        <li><a href="#" class="ativa">Página Inicial</a></li>
            <li><a href="servicos">Serviços</a></li>                  
            <li><a href="entretenimento">Entretenimento</a></li>
            <li><a href="festas-e-decoracoes">Festas e Decorações</a></li>
            <li><a href="bares-e-restaurantes">Bares e Restaurantes</a></li>    
            <li><a href="beleza-e-estetica">Beleza e Estética</a></li>
            <li><a href="hoteis-e-pousadas">Hotéis e Pousadas</a></li>
            <li><a href="esportes-e-suplementos">Esportes e Suplementos</a></li>
            </ul>   
But I want it to be in php due to the database I created for url friendly, for example: /categories/services
How do I continue my menu with active class, but being done in php?
The code is for a getMenu but I don’t know if it’s correct.
public function getMenu(){
        $pegar_categorias = "SELECT * FROM 'categorias' ORDER BY id DESC";
        $executar = self::conn()->prepare($pegar_categorias);
        $executar->execute();
        if($executar->rowCount()==0){}else{
            while($categoria = $executar->fetchObject()){
                echo '<li><a href="'.Path.'/categoria/'.$categoria->slug.'">'.$categoria->titulo.'';
                echo '</li>';
            }
        }
    }
Thank you!
Where is the php code? At least php should have information about which page is the current and this information should be related to the menu.
– Daniel Omine
I edited and added php code!
– Jessica Elena
Makes a
echo $_SERVER['REQUEST_URI']; exit;right at the top of the page and you might get a sense of where to start.– Daniel Omine
Following what @Danielomine said, compare the
$categoria->slugwith the$_SERVER['REQUEST_URI']to put an "active" class in the read that is related to the page that is open– Daniel Costa