Need some help with a menu-bar function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martien van Wanrooij

    Need some help with a menu-bar function

    I often use a function to create a list of links that are included in
    several sites and disable the link that refers to the site itself

    <?php
    function maakZoNodigLink ($omschrijving, $verwijzing)
    {
    $locatie = $_SERVER['PHP_SELF'];
    if (strstr($locati e, $verwijzing)) //actual page
    should not be linked
    echo $omschrijving." <br>\n";
    else echo ("<a href = \"$verwijzing\" >$omschrijvin g</a><br>\n"); //other
    pages are linked }
    ?>

    Somewhere else in the page I do something like:
    <?php
    maakZoNodigLink ("Hoofdpagina", "main.php") ;
    maakZoNodigLink ("Geschiedenis" , "gesch.php" );
    ?>

    Although it works okay, I have to do some editing when I use the function
    for another site. E.g. in this example every link is followed by a <br> and
    when want to create a menu bar like [home][hobby's][contact] and the actual
    link should not be underlined, I have to realise a lot of changes *within*
    the function itself.
    I have been thinking about possibilities to create an additional variable
    like $separator = "<br>" but I don't know where to locate it. Besides I
    wonder if there is a more efficient way then callling the maakZoNodigLink
    function several times, as I do in the example above.
    Would like some feedback because I have the feeling that I am doing things
    in a more complicated way then I should do :-)
    Thanks for any help,

    Martien van Wanrooij


  • Jon Kraft

    #2
    Re: Need some help with a menu-bar function

    "Martien van Wanrooij" <info@martienva nwanrooij.nl> wrote:
    [color=blue]
    > <?php
    > function maakZoNodigLink ($omschrijving, $verwijzing)
    > {
    > $locatie = $_SERVER['PHP_SELF'];
    > if (strstr($locati e, $verwijzing))
    > echo $omschrijving." <br>\n";
    > else echo ("<a href = \"$verwijzing\" >$omschrijvin g</a><br>\n");
    > //other
    > pages are linked }
    > ?>
    >
    > Although it works okay, I have to do some editing when I use the
    > function for another site. E.g. in this example every link is followed
    > by a <br> and when want to create a menu bar like
    > [home][hobby's][contact] and the actual link should not be underlined,[/color]

    You could add a parameter which has a default value, e.g.:

    function maakZoNodigLink ($omschrijving, $verwijzing, $separator="<br
    />")
    {
    $locatie = $_SERVER['PHP_SELF'];
    if (strstr($locati e, $verwijzing))
    echo $omschrijving.$ separator."\n";
    else echo ("<a href = \"$verwijzing\" >$omschrijvin g</a>".
    $separator."\n" );
    }

    If you want to change the layout, give the additional parameter with a
    different separator, e.g.:

    echo "[";
    maakZoNodigLink ("Hoofdpagina", "main.php", "][");
    maakZoNodigLink ("Geschiedenis" , "gesch.php" , "]");

    The original call to the function will still work as well:
    maakZoNodigLink ("Geschiedenis" , "gesch.php" );

    HTH;
    JOn




    HTH;
    JOn

    Comment

    • Martien van Wanrooij

      #3
      Re: Need some help with a menu-bar function


      "Jon Kraft" <jon@jonux.co.u k> schreef in bericht
      news:Xns948DB6C CFD021jonjonuxc ouk@130.133.1.1 7...[color=blue]
      > You could add a parameter which has a default value, e.g.:
      >
      > function maakZoNodigLink ($omschrijving, $verwijzing, $separator="<br[/color]

      [...][color=blue]
      > If you want to change the layout, give the additional parameter with a
      > different separator, e.g.:
      > echo "[";
      > The original call to the function will still work as well:
      > maakZoNodigLink ("Geschiedenis" , "gesch.php" );[/color]
      Thank you John, this really helps a lot :-)

      Martien.


      Comment

      Working...