Jump to content

HTML/CSS Navigation Bar (on all pages!)

Go to solution Solved by Brenz,

You will need a web server for this, look into XAMPP if you want to just run it locally for now. Once you have one set up you can use PHP's include function to include another file like:

<?php include('navigation.html'); ?>

Then you just need to put your navigation code into that file and include it on each page.

Hello people of LTT forums!

 

I'm creating a website for myself(I don't have a web server so I cant host right now) and I just finished creating a horizontal navigation bar. I want to include this on all pages, however I don't want to copy/paste the code from it on every single page. Does anyone know how to do that?

 

Thanks,

chargerjake

PC SETUP: | i5-4440 3.1 GHz | MSI Z97s Krait | EVGA GTX 970 | G.Skill Value 8GB | WDC Blue 500GB | NZXT S340

MOBILE SETUP: | Apple iPhone 6 | iOS 10b4 | Apple Watch Stainless Steel w/ Black Sport Band | WatchOS 3b4

 

Steam: chargerjake | Origin: chargerjake

 

Link to comment
https://linustechtips.com/topic/302424-htmlcss-navigation-bar-on-all-pages/
Share on other sites

Link to post
Share on other sites

You will need a web server for this, look into XAMPP if you want to just run it locally for now. Once you have one set up you can use PHP's include function to include another file like:

<?php include('navigation.html'); ?>

Then you just need to put your navigation code into that file and include it on each page.

Link to post
Share on other sites

poor coding but you could use an iframe for the main section? i really wouldn't recommend this, using php to change the text based on get data something like

<?php if(isset($_GET['home'])) { echo "home page stuff";} else if(isset($_GET['other'])) { echo "other page stuff";}?>

then all links would be index.php?home, index.php?other.

 

this would allow you to have one page with just your main content changing based on the get value.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

It is very possible, and quite easy to do. Of the solutions provided, only the one by @Brenz makes sense, you should definitely use the include function

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to post
Share on other sites

I've always used php's include method or require if it only is included once I believe. You are right that there is most likely a better way of going about things than copy and pasting though. Good luck on your website.

<?php include "header.php" ?>
Link to post
Share on other sites

You will need a web server for this, look into XAMPP if you want to just run it locally for now. Once you have one set up you can use PHP's include function to include another file like:

<?php include('navigation.html'); ?>

Then you just need to put your navigation code into that file and include it on each page.

Does this work in an HTML document? It looks like XAMPP is for PHP only, and I do not know PHP(yet).

PC SETUP: | i5-4440 3.1 GHz | MSI Z97s Krait | EVGA GTX 970 | G.Skill Value 8GB | WDC Blue 500GB | NZXT S340

MOBILE SETUP: | Apple iPhone 6 | iOS 10b4 | Apple Watch Stainless Steel w/ Black Sport Band | WatchOS 3b4

 

Steam: chargerjake | Origin: chargerjake

 

Link to post
Share on other sites

Does this work in an HTML document? It looks like XAMPP is for PHP only, and I do not know PHP(yet).

 

Nope, you will need to run XAMPP, rename your file to .php instead of .html and use the code above.

 

What you want to do can only be achieved server-side, HTML is only client-side.

Link to post
Share on other sites

Nope, you will need to run XAMPP, rename your file to .php instead of .html and use the code above.

 

What you want to do can only be achieved server-side, HTML is only client-side.

So I don't actually have to put PHP in the file, except for the include statement?

PC SETUP: | i5-4440 3.1 GHz | MSI Z97s Krait | EVGA GTX 970 | G.Skill Value 8GB | WDC Blue 500GB | NZXT S340

MOBILE SETUP: | Apple iPhone 6 | iOS 10b4 | Apple Watch Stainless Steel w/ Black Sport Band | WatchOS 3b4

 

Steam: chargerjake | Origin: chargerjake

 

Link to post
Share on other sites

Exactly, you can just use HTML with PHP code mixed in using <?php   php_code_here    ?>

Thank you sir! I appreciate it a lot.

PC SETUP: | i5-4440 3.1 GHz | MSI Z97s Krait | EVGA GTX 970 | G.Skill Value 8GB | WDC Blue 500GB | NZXT S340

MOBILE SETUP: | Apple iPhone 6 | iOS 10b4 | Apple Watch Stainless Steel w/ Black Sport Band | WatchOS 3b4

 

Steam: chargerjake | Origin: chargerjake

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×