Menu include for other pages

Asked

Viewed 980 times

1

Speak guys, I’m trying to learn in php race, I’m developing a home site and I would like my Menu to stay fixed on all pages of this my site.

This is the.php menu file that 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 which is mixed with the top 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 on my.php network page (for example), which I want to insert I have put only the following command for testing:

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

However Nothing works, I even thought it was my WAMP settings, I tried 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". Is the syntax correct for me, any personal observations? Taking advantage of the line... Is it feasible to save all my development pages with php extension? Since it can "read" or better said, differentiate codes from tags like and the very . Thanks in advance, hugs.

  • <? php cannot have space

  • "It doesn’t work" in what sense?

  • It does not work in the sense of not performing the include function on the networks.php page, the menu is not passed to this page...

  • The original code is correct, with <?php include "menu.php"; ?>

  • tries to exchange "include" for "require"

  • I made the exchange and yet the same mistake persists.

  • Enter the complete file code, networks.php

Show 2 more comments

1 answer

1


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

One include should contain only the code you want it to contain. As in your example, your include is intended to be a menu nav, so it should contain only the HTML menu, not a full page, with the tags <html>, <head>, <body> etc..

As the include is basically just an integral part of the page, the very page where include is that should contain the CSS, scripts and the main tags of the page structure, not include.

In your case, include should contain only:

<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 mother-page and will be part of the page’s HTML, suffering all the effects of CSS and scripts they may have in the code of the page where it is included.

Browser other questions tagged

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