0

I got a problem that I want to solve. I created a style.css, index.html, and cmenu.css (cmenu for coolmenu) file. In my cmenu.css I describe how my coolmenu looks like.

Here is my site: http://pjgini.funpic.de/. My menu links are located in index.html. By creating a new site I must copy the same links in the new site. I dont want to copy and paste all the links stuff in each of my sites.

This are my menu links in my index.html file:

 <div id="klappmenu">
 <ul id="liste">
 <li><a href="#">Kategorie 1</a>
 <ul>
 <li><a href="/Seite.htm">Unterseite 1.1</a></li>
 <li><a href="/Seite.htm">Unterseite 1.2</a></li>
 <li><a href="/Seite.htm">Unterseite 1.3</a></li>
 </ul>
 </li>
 ...
 </div> 

Now I want to include them in any html document!

  • do you want to include cmenu file in style.css file? – Hushme Jul 27 '13 at 22:37
  • No. Look at the source of my site. You can see my menu-links. these
    • . I want to create a completely new file where my menu links are located and try to find out a method to link them all the new sites i created. As same as the css file. Im creating a completely new css file and every site can access it with this code up there.
    – Manh Khôi Duong Jul 27 '13 at 22:42
  • u want to include menu html file in each html document? – Hushme Jul 27 '13 at 22:51
  • view-source:file:///home/jimmy/Desktop/PJGini/index.html look there: – Manh Khôi Duong Jul 27 '13 at 22:53
  • I edited my problem description. I must write these codes in each site ! I dont want it anymore. I wanna create a completely new file where my menu links are located and I can include them with a code. – Manh Khôi Duong Jul 27 '13 at 22:55
  • You're running Apache. You could [include a common file with PHP](http://www.w3schools.com/PHP/php_includes.asp) – Trojan Jul 27 '13 at 22:58

2 Answers2

2

PHP seems to be the best way to go.

Put your menu in a HTML file called main-menu.html. Then, everywhere you want your menu to show, include this html code but make sure you save your files as .php and that the path to your menu's html file is correct.

<?php
    include_once("path/to/main-menu.html");
?>

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. If you are new to PHP and want to get some idea of how it works, try the introductory tutorial. After that, check out the online manual.

Source. php.net

Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
  • I ve got a question: DO i have to write documents in the php language? Can I use the html language in my PHP file? – Manh Khôi Duong Jul 28 '13 at 12:39
  • @ManhKhôiDuong You can use any HTML formatting you like, it will be rendered as HTML just as any normal `.html` file. The thing about PHP is that when you call PHP (the code inside the PHP tags ``), the server does something, in this case it makes sure `main-menu.html` is included in the html file. You can't force/check something like that in HTML. I added a quote in my post. – Bram Vanroy Jul 28 '13 at 13:33
0

There are two ways of doing this. First of all, create an html file that only includes your menu's html (no css, nothing else). Let's say this is named "yourMenuBar.html". You can use an SHTML include by renaming your original page to "yourpage.shtml" and then adding the code:

<!--#include file="yourMenuBar.html" -->

to the page.

If you prefer php, you can also accomplish this as:

<?php
include_once("yourMenuBar.html");
?>

In this case, you would need to change your page extension to "yourpage.php".

Elie Zeitouni
  • 251
  • 1
  • 4
  • 13
  • doesnt work for me. look here: http://pjgini.funpic.de/index.shtml – Manh Khôi Duong Jul 27 '13 at 23:27
  • Ah, I apologise for being unclear. You put the include where you want the content to go. So while you put it at the top of the page (above the DocType), I believe you actually want it inside your Menu 1 DIV. Sorry for the late response, I went to sleep! – Elie Zeitouni Jul 28 '13 at 15:42