Search code examples
phphtmlcssphp-include

Using php include with multiple sub directories


Hello i recently just got my web server to run all .html files as .php files which now allows me to use the php include function, which is very useful.

However i have multiple sub directories with multiple files in each.

Homepage --banners --banner2.html --banner2.html --signs --sign1.html

and so on. The problem here is im trying to use include for my top nav bar. when i include the bar in the sub files, for example banner2.html it wont correctly link.

nav.php

<ul class="nav navbar-nav">
                    <li>
                        <a href="about.html">About</a>
                    </li>
                    <li>
                        <a href="Services.html">Services</a>
                    </li>
                    <li>
                        <a href="index.php">Contact</a>
                    </li>

                    <li>
                        <a href="Login/Sign-In.html">Login</a>
                    </li>

                    <li>
                        <a href="Login/logout.php">Logout</a>
                    </li>

                    <li>
                        <a href="PHP/Cart.php"><img src="images/Cart.gif" style="height: 20px; width:20px;"> Cart</a>


                    </li>

                </ul>

in the nav bar is a link to about.html normally i would do the

<a href="../about.html">about</a>

however i cant do that when every file is going to share the same navigation bar. How can I fix this?


Solution

  • I have answered my own quest and feel silly for even asking the question. I just used absoulte paths

    nav.php

    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li>
                            <a href="http://domain.com/about.html">About</a>
                        </li>
                        <li>
                            <a href="http://domain.com/Services.html">Services</a>
                        </li>
                        <li>
                            <a href="http://domain.com/index.php">Contact</a>
                        </li>
    
                        <li>
                            <a href="http://domain.com/Login/Sign-In.html">Login</a>
                        </li>
    
                        <li>
                            <a href="http://domain.com/Login/logout.php">Logout</a>
                        </li>
    
                        <li>
                            <a href="http://domain.com/PHP/Cart.php"><img src="images/Cart.gif" style="height: 20px; width:20px;"> Cart</a>
    
    
                        </li>
    
                    </ul>