Jump to content

Placing A Page In A Function


devilsvein

Recommended Posts

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

Link to comment
Share on other sites

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 by PaulRyan
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.