devilsvein Posted December 29, 2012 Share Posted December 29, 2012 Im basically working on a site in which I want to display a menu bar on every page. As this site will be built with many pages i feel it would be easier to simply create a function with the menu bar inside it. I have a few questions which i would appreciate if someone could answer. <ul> <li><a href="#">Home</a></li> <li><a href="#">about</a></li> </ul> Let say I have this code above. would i simply be able to do: function menu () { <li><a href=#>Home</a></li> <li><a href=#>about</a></li> </ul> } and call the function on specific areas on the page i want it to be displayed. after requiring that file name. Also curious on if i can do if statements inside that function that display certain menu links depending on the outcome of the condition Thanks Quote Link to comment https://forums.phpfreaks.com/topic/272491-placing-a-page-in-a-function/ Share on other sites More sharing options...
PaulRyan Posted December 29, 2012 Share Posted December 29, 2012 (edited) Try something like this: <?PHP //### Function to display menu function displayMenu($menu='') { //### Check to see which menu to show using is else if($menu == 'home') { $menuHTML = '<ul> <li><a href="#">Home Link</a></li> <li><a href="#">Home Link</a></li> </ul>'; } else if($menu == 'profile') { $menuHTML = '<ul> <li><a href="#">Profile Link</a></li> <li><a href="#">Profile Link</a></li> </ul>'; } else { $menuHTML = '<ul> <li><a href="#">Default Link</a></li> <li><a href="#">Default Link</a></li> </ul>'; } //### Return select menu return $menuHTML; } //### Displays default links echo displayMenu(); //### Displays home links echo displayMenu('home'); //### Displays profile links echo displayMenu('profile'); ?> Edited December 29, 2012 by PaulRyan Quote Link to comment https://forums.phpfreaks.com/topic/272491-placing-a-page-in-a-function/#findComment-1402066 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.