Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include menu on every page

Let's say I have a simple CSS layout and my menu is a column on the side. This menu is going to be on every web page (About 10 web pages). If I have items on this menu in the form of links and such, how can I make it so that if I add a link on one page, it will add it to all pages? Would you just make it a PHP page and in that <div> element include a PHP file called menu or something, and just edit that PHP file (so I only have to edit that file and not every web page)?

like image 911
ranzy Avatar asked Aug 30 '25 18:08

ranzy


2 Answers

If this is raw PHP (no frameworks) then you simply include it.

include 'sidebar.php';

Make sure that you can access the file from where you are including it though. If you have files in a folder called foo for example, and accessed via example.com/foo/somefile.php you will have to change the include statement to include('../sidebar.php'); assuming sidebar.php is in the root.

like image 74
Josh K Avatar answered Sep 02 '25 08:09

Josh K


As stated above, and include would do.

Drop this on every page you want your menu to appear:

<?php include "/yourMenu.php"; ?>

Just save the menu code as yourMenu.php and put it in the root and you are good to go.

like image 30
Peachy Avatar answered Sep 02 '25 07:09

Peachy