0

Hello,

I have a menu in a webpage. I am looking to make the code reusable for another page, that way I can manage the links in one place rather than multiple page. Anyone know a way to do this?

Thanks

Drjay

4
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by JorgeM
1

Hey,

You could try using a header system (Let me explain):

Basically, have a file called: header.php which contains all the content around the where the different pages will exist (so like index.php, about.php etc) and then on each page you can call the header.php. This meaning that if you wanted to change the links then you can do this easily by just changing the header.php file and it will change every single page that has included the header..

Another solution could be to create a function:

<?php
 // links.php
function links()
{
   echo '<a href="link1.php">link 1</a>';
}
?>

<?php
   // index.php
     // include the links function
     include ('links.php');

     links();
?>

Hope this helps :)

0

Hello,

Thanks for the idea. I actually tried but failed to implement this since it seems I don't have PHP is working on my PC and Mac.

Do I have to start the Apache server to start the get php to work?

Because even this isn't really working for me on my browser!

<?php
    echo "Hi";
?>

Thanks,

Drjay

0

Yes, you need to have a webserver running with PHP enabled to be able to view this.

I recommend XAMPP since you seem like a beginner.

0

Just would like to add that this is a common approach for web development. Depending on the server side scripting language, the technique may be different. For example, if this site was developed in asp.net, you could use master pages.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.