php function to "print" the whole navbar
Done it this way:
Current page that is being executed is in need of a navigation bar - calls the functionFile.php by:
include("relativeDirectory/functionFile.php");
The function inside functionFile.php (among many other functions, just so you don't think I did this with the sole purpose of showing the navigation bar) prints out the page that creates the navbar(in this case navbarPage.php) to the page where it is executed. It also has an argument that says which one of the buttons on the navbar is selected.
function printnbar($selected){ include 'navbarPage';}
and in the navbarPage.php page I did something like:
<body><style style type = "text/css" scoped> .buttondefault{ unselected button stuff} .buttonselected{ selected button stuff}</style><?php$sel1 = $sel2 = $sel3 = "class='buttondefault'";switch ($selected) { case "NavButton1": $sel1 = "class='buttonselected'"; break; case "NavButton2": $sel2 = "class='buttonselected'"; break; case "NavButton3": $sel3 = "class='buttonselected'"; break;}?><divs,dropdowns,whatever> <button <?php echo $sel1; ?>>YourButton1</button> <button <?php echo $sel2; ?>>YourButton2</button> <button <?php echo $sel3; ?>>YourButton3</button></divs,dropdowns,whatever></body>
And there it is! I can print out a navigation bar in any page with the button I want selected just by typing:
printnbar("ButtonOnTheNavbar");
Hope this may help someone in the future! And thanks to everyone who helped me achieve this.
Tell me if you have a better way!
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 accountSign in
Already have an account? Sign in here.
Sign In Now