Include menu for other pages

1

Talk, I'm trying to learn in the php race, I'm developing a Home Site and I'd like my Menu to stay on every page of my site.

This is the file menu.php which in this case is what I want to use on all other pages with include:

<html>
<head>
    <title>ThreePower</title>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" type="text/css" href="style.css" /> 
<body>       
    <div id="nav">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="redes/redes.php">Redes</a></li>
            <li><a href="#">Fóruns</a>
                <ul>
                    <li><a href="#">Vivao</a></li>
                    <li><a href="#">Clube</a></li>
                    <li><a href="#">Stack</a></li>
                    <li><a href="#">Flash</a></li>
                </ul>
            </li>
            <li><a href="#">Programação</a>
              <ul>
                    <li><a href="#">JAVA</a></li>
                    <li><a href="#">Jquery</a></li>
                    <li><a href="#">Javascript</a></li>
                    <li><a href="#">PHP</a></li>
               </ul>
            </li>
            <li><a href="#">Projetos</a>
                <ul>
                    <li><a href="#"> Scripts </a></li>
                </ul>

            </li>
        </ul>

    </div>

</body>

</head>

This is my Style that is mixed with the above html code:

<style type="text/css">

body {
   background-repeat: no-repeat;
  -webkit-background-size: 100%;
  -o-background-size: 100%;
  -moz-background-size: 100% 100%;
  width: 100% 100px;
  height: 800px;
}

 
#nav {
    float: left;
    margin: 100px;
    margin-top: -2px;
    margin-right: 120px;
    margin-left: 340px;
}

 

#nav ul {

    font: 16px arial, tahoma, verdana;
    list-style: none;
    margin: 0;
    padding: 0;

}

 

#nav ul li {
    float: left;
    position: relative;
    display: block;

}

 

#nav ul li a {
    color: #555;
    background: #FFF;
    text-decoration: none;
    margin: 0 1px;
    padding: 15px 20px;
    border-top: 1px solid #555;
    display: block;

}
#nav li ul {
    display: none;
}
#nav ul li a:hover {
    background: #066;
    color: #FFF;
}
#nav li:hover ul {
    display: block;
    position: relative;
}
#nav li:hover li {
    float: none;
    font-size: 12px;
}
#nav li:hover a {

    background: #333;
    opacity: 0.5;
    color: #FFF;
}
#nav li:hover li a:hover {
    background: #222;
}
#textos{
    height: 500px;
}
</style>

Now in my web.php page (for example), which I want to insert I have put only the following command to test:

<? php include "menu.php"; ?>

But nothing works, I even thought it was the settings of my WAMP, I fucked and found a php option called Include and it was disabled, so I enabled it and nothing worked, the 2 folders are in the same place inside "WWW". For me is Syntax correct, any personal observation? Taking advantage of the ... Is it feasible for me to save all my development pages with php extension? Because it can "read" or better say, differentiate codes from tags like and himself. Thanks in advance, hugs.

    
asked by anonymous 04.01.2018 / 22:34

1 answer

1

As you said " be learning in the race", this answer will help you.

An include should contain only the code that you want it to contain. As in your example, your include is meant to be a nav menu, so it should contain only the HTML of the menu, not a full page, with the tags <html> , <head> , <body> etc. p> Because include is basically just an integral part of the page, the page itself where the include is supposed to contain the CSS, scripts, and main tags of the page structure, not the include .

In your case, the include should only contain:

<div id="nav">
    <ul>
        <li><a href="#">Home</a></li>
        <li><a href="redes/redes.php">Redes</a></li>
        <li><a href="#">Fóruns</a>
            <ul>
                <li><a href="#">Vivao</a></li>
                <li><a href="#">Clube</a></li>
                <li><a href="#">Stack</a></li>
                <li><a href="#">Flash</a></li>
            </ul>
        </li>
        <li><a href="#">Programação</a>
          <ul>
                <li><a href="#">JAVA</a></li>
                <li><a href="#">Jquery</a></li>
                <li><a href="#">Javascript</a></li>
                <li><a href="#">PHP</a></li>
           </ul>
        </li>
        <li><a href="#">Projetos</a>
            <ul>
                <li><a href="#"> Scripts </a></li>
            </ul>

        </li>
    </ul>

</div>

This code will be included (hence the name include ) in the parent and will be part of the HTML of the page, suffering all the effects of CSS and scripts that may have in the page code where it is included.

    
05.01.2018 / 00:05