Skip to content Skip to sidebar Skip to footer

How To Make Navbar Constant Across Multiple Pages?

I have looked at prevous questions about this and people say php and have not found an answer. how do I convert my navbar to php and use it in multiple html pages. Could someone te

Solution 1:

Say you have about.php and home.php in the root of your website. Create a directory called partials (or whatever), go into partials and put the contents of your navigation HTML in a file called nav.php. Then in about.php and home.php, use this where you want to include the navigation code

<?phpinclude'partials/nav.php'; ?>

Solution 2:

Here is one way (extremly basic):

Create a PHP file called index.php

<!DOCTYPE html><html><body><header><?phpinclude'header.php';

    /**
     * say you wanted a different header for shop
     * if($_GET['page'] === 'shop') {
     *      include 'header-shop.php';
     * } else {
     *      include 'header.php';
     *}         
     */?></header><divid="main"><?phpinclude$_GET['page'].'.php'; // assuming your storing your pages in same path as index?></div><footer><?phpinclude'footer.php';
    ?></footer></body></html>

Then a header.php

<divclass="tabs"><ul><li><ahref="index.php?page=contact">Contact</a></li><li><ahref="index.php?page=shop">Shop</a></li></ul></div>

And create your page files contact.php, shop.php ect.

Updated to a slightly more elaborate example to give you the idea.

Post a Comment for "How To Make Navbar Constant Across Multiple Pages?"