Same menu of links on each page

A

Anonymous

Guest
Is there some way to do this with php?

I have Dreamweaver, but I am perfectly able to do lots of stuff with just html source code. I know a tiny bit of perl and php.

see http://shakahara.com/garden1.html

See the menu of links along the top of the page. I have 9 pages with the same menu. I may want to add more. Every time I add a new page, say I want to add a page 10, then later a page 11 -- I don't want to have to open up all 11 pages and copy the new lines of html to each page.

I was thinking I could use a menu in a separate file and put an ssi directive in each page to include the menu? That way I would only have to modify one file, the menu file. I don't think I want to mess with frames.

But will frames work faster than ssi, esp for people with a dialup connection?

any hints for me?

Then it occurred to me that they may be some php code that will call up the same file, within every file that I put the code in.

Can anyone give me some hints on how to do this?
 
frames are usually not the way to go.. you should avoid them as soon as possible.
You cans ave the code of the links into a variable and then output on all pages only that variable (include a file containing that var, and then output the variable)

or... you way want to populate the links from an array:

Code:
//Pagelinks.php
<?php
$array = array(
  'Page 1' => 'page_1.html',
  'Page 2' => 'page_2.html',
  'Page 3' => 'page_3.html',
  'Page 4' => 'page_4.html'
);
?>

//On every page you make
<?php
include ("pagelinks.php");
foreach($array as $name => $link)
{
   echo(' <a href="'.$link.'">'.$name.'</a> ');
}
?>

On migger pages i wouldve used a tempalte engine for that at i hate iutputing html directly via php...
 
Thanks Alexei Kubarev.

I am having trouble learning php and mySQL from their respective official reference sites. What little I've learned is from tutorials. Then after about 2 weeks I forget what i've learned.

I have figured out how to make your code work. But now, looking back on simpler methods, I'm wondering now why not simply make my menu in the form of html code instead of a php array. In other words, on each page where I want the menu to display put:

Code:
<?php include('menu1.txt')?>

and then construct menu1.txt exactly the way I want it to look -- the same on every page where I put the include statement, construct the meny like this:

Code:
<table border="1" cellpadding="8" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td>
<a href="introduction.html"><font size="1" face="Verdana">Home</font></a>
<font size="1" face="Verdana"> | Veganic Garden  page </font>
<a href="page_1.html"><font size="1" face="Verdana">1</font></a>
<a href="page_2.html"><font size="1" face="Verdana">2</font></a>
<a href="page_3.html"><font size="1" face="Verdana">3</font></a>
<a href="page_4.html"><font size="1" face="Verdana">4</font></a>
</td>
  </tr>
</table>

(the file can be a simple text file because the html code that it needs ahead of it and after it is in the file that has the "include" statement.)

I guess your answer would be that I could construct a php page defining an array, then contstruct another simple text page plugging the array element variable names into the menu, instead of writing out the array values into the menu -- and that this way I could speed up the construction of different-looking menus for different pages ??

Let's see, so in my menu above, instead of putting "page_1.html" I could write in some code that specifies "page 1". In other words I wouldn't have to write out the whole name of the page that the link is to, just the variable, in the array, that specifies that page.

So let's see, the in each page where I want a menu to be would be

Code:
<?php include ("menu1.txt")?>
or menu2.txt, etc

And now I have to figure out how to construct my various menu?.txt files, to make each of my menus look the way I want them to look. Let's see, one menu could be something like...

Code:
<<table border="1" cellpadding="8" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td>
<a href="introduction.html"><font size="1" face="Verdana">Home</font></a>
<font size="1" face="Verdana"> | Veganic Garden  page </font>
<?php
include ("test1.php");
foreach($array as $name => $link)
{
   echo(' <a href="'.$link.'">'.$name.'</a> ');
}
?>


</td>
  </tr>
</table>

However the numerals in the foreach loop are displaying in the defualt font and font size, instead of in verdana. So I have to get the font info into the loop, somehow. That shouldn't be difficult. I jsut have to do more php tutorials I think.

Sorry, feel free to ignore this while I go back and do more php tutorials. I assume I would put the text right after the "echo" command.
 
Code:
echo ('<a href="'.$link.'"><font size="1" face="Verdana">'page','.$name.'</font></a> ');
}

No, that isn't working out.

Code:
echo ('<a href="'.$link.'"><font size="1" face="Verdana">page'.$name.'</font></a> ');

Ok that seems to do the trick.

I need to go back and start doing php tutorials from page one -- if I can find the tutorial again, that I learned it from the first time. I have forgotten so much. I prefer languages that aren't so "concise". For example, if I name variables "$name" and "$link" I won't be likely to remember what they are for, but if I name them "$menuchoice_displayed_characters" and "$filename_that_displayed_characters_link_to" I might remember, a week later, what the array does.

Even just $menu_display and $filename would help me remember what the array is for. But if I see $name and $link I will be lost. I'll be thinking "name of what." and "link, what link?" It isn't a matter of 2 weeks, it is a matter of one day, or even just 2 hours later. In the span of 2 hours, or less, I could forget what name and link are substitutes for. Yet I know most programmers choose very brief variable names, like these. So I am wondering how you remember, later, what they refer to. Is it just context?
 
Back
Top