Include menu on all pages

0

I made the menu of a system I'm doing in html and php, I wanted to insert this menu on all pages, but I wanted to change the active menu according to the open page, is it possible? My current menu is in html for now:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/jquery-3.2.1.min.js"></script>

<script src="js/bootstrap.min.js"></script>
<script defer src="js/fontawesome-all.min.js"></script>



<?php
require 'config.php';
//require 'verificalogin.php';
$sql = new Sql();
$nome = $_SESSION['nome'];
?>

<link rel="stylesheet" href="css/cssbase.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Administrativo DoUp</title>
</head>
<body>
    <!-- inicio da navbar -->
    <header>
        <div class="navbar navbar-default navbar-fixed-top" role="navigation">
            <div class="container"> 
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span> 
                    </button>
                    <img src="imagens/logo.png" id="logo">
                </div>
                <div class="collapse navbar-collapse">
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="#">Inicio</a></li>
                        <li ><a href="noticias.php">Noticias</a></li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                <i class="fas fa-user-circle fa-lg"></i> 
                                <strong>Igor de Oliveira</strong>
                                <i class="fas fa-caret-down "></i>
                            </a>
                            <ul class="dropdown-menu">
                                <li>
                                    <div class="navbar-login">
                                        <div class="row">
                                            <div class="col-lg-8">
                                                <p class="text-left"><strong>Igor Oliveira</strong></p>
                                                <p class="text-left small">[email protected]</p>
                                                <p class="text-left small">Praia da Costa</p>
                                                <p class="text-left">
                                                    <a href="#" class="btn btn-primary btn-block btn-sm">Alterar Senha</a>
                                                </p>
                                            </div>
                                        </div>
                                    </div>
                                </li>
                                <li class="divider"></li>
                                <li>
                                    <div class="navbar-login navbar-login-session">
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <p>
                                                    <a href="#" class="btn btn-danger btn-block">Deslogar</a>
                                                </p>
                                            </div>
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </header>
</body>
</html>
    
asked by anonymous 09.01.2018 / 01:52

2 answers

1

Hello, you can create separate files in php and give require_once to import it into any part of the page, even in other files, so it is very useful not to be rewriting the code every time in each file

Example:

header.php

<header>
    Aqui você faz seu header todo dentro de um arquivo chamado = header.php
</header>

Then just give one:

<?php require_once "header.php"; ?>

In the part that wants to insert the header

<!DOCTYPE html>
<html>
    <head>
        <title>Título da página</title>
        <meta charset="UTF8"/>
    </head>
    <body>
        <?php require_once "header.php" ?>
    </body>
</html>
    
09.01.2018 / 14:02
-1

You can do this with JQuery, for example:

<html>
<head>
<title>Include Common Files</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div id="header"></div><br />
<div id="content">
Main Content
</div><br />
<div id="footer"></div>
<script>
$("#header").load("header.html");
$("#footer").load("footer.html");
</script>
</body>
</html>

You have a more detailed explanation here, if you want to understand better: link

    
09.01.2018 / 02:28