Need help to code collapsing menu

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rigga

    Need help to code collapsing menu

    Hi,

    I am trying to code a menu for a webpage, the menu is broken up to groups
    i.e:

    Home
    Group1
     menuitem1
     menuitem2
     menuitem3
    Group2
      menuitem1
      menuitem2
     menuitem3
    And so on.

    What I want to achieve is that the groups are shown in a collapsed state
    depending on the page which is currently being displayed i.e so it starts
    out like this

    Home
    Group1
    Group2

    If you click on Group1 it loads the first menuitem page and highlights it
    and redraws the page expanding that group i.e. (note * denotes highligthed)


    Home
    Group1
      menuitem1
       menuitem2
       menuitem3 
    Group2

    And the same would apply if you click on Group2 i.e:


    Home
    Group1
    Group2
      menuitem1
        menuitem2
        menuitem3 

    What is the best way to go about this? I have coded it 'the long way' where
    there is lots of duplication of code.

    I hope this all makes sense and that I have explained it clearly.

    I am new to php so would really appreciate your help as I am totally at a
    loss on how to best do this.

    Many thanks

    Rigga
  • SOR

    #2
    Re: Need help to code collapsing menu

    <comp.lang.ph p , rigga , rigga@hasnomail .com>
    <42cec215$0$220 96$ed2619ec@ptn-nntp-reader01.plus.n et>
    <Fri, 08 Jul 2005 19:12:36 +0100>
    [color=blue]
    > What is the best way to go about this? I have coded it 'the long way' where
    > there is lots of duplication of code.
    >
    > I hope this all makes sense and that I have explained it clearly.
    >
    > I am new to php so would really appreciate your help as I am totally at a
    > loss on how to best do this.
    >[/color]

    Using includes should make it quite easy - even for a newbie like me .

    blah.php?pass=1 on your main group link .

    Assuming you have the nav menu as a include you could do a 'if' and if
    the value is 1 then display the extra sub menu links .

    Although , You would need the ?pass=1 on all the sub links as well or
    the sub menu would disappear when you clicked on sub link .

    As a fellow php newbie i've found getting stuff working first and then
    trying to tweak and fine tune it later can be useful .

    Comment

    • rigga

      #3
      Re: Need help to code collapsing menu

      SOR wrote:
      [color=blue]
      > <comp.lang.ph p , rigga , rigga@hasnomail .com>
      > <42cec215$0$220 96$ed2619ec@ptn-nntp-reader01.plus.n et>
      > <Fri, 08 Jul 2005 19:12:36 +0100>
      >[color=green]
      >> What is the best way to go about this? I have coded it 'the long way'
      >> where there is lots of duplication of code.
      >>
      >> I hope this all makes sense and that I have explained it clearly.
      >>
      >> I am new to php so would really appreciate your help as I am totally at a
      >> loss on how to best do this.
      >>[/color]
      >
      > Using includes should make it quite easy - even for a newbie like me .
      >
      > blah.php?pass=1 on your main group link .
      >
      > Assuming you have the nav menu as a include you could do a 'if' and if
      > the value is 1 then display the extra sub menu links .
      >
      > Although , You would need the ?pass=1 on all the sub links as well or
      > the sub menu would disappear when you clicked on sub link .
      >
      > As a fellow php newbie i've found getting stuff working first and then
      > trying to tweak and fine tune it later can be useful .[/color]
      Could you explain further?, how would I get it to highlite the active link?

      Comment

      • SOR

        #4
        Re: Need help to code collapsing menu

        <comp.lang.ph p , rigga , rigga@hasnomail .com>
        <42cf86bd$0$286 5$ed2e19e4@ptn-nntp-reader04.plus.n et>
        <Sat, 09 Jul 2005 09:11:39 +0100>
        [color=blue]
        > Could you explain further?, how would I get it to highlite the active link?
        >[/color]

        www.snipe.net this guys nav menu uses the sort of thing you want to do -
        it might be worth a email to ask him for the source code as his method
        is probably better than mine .

        Comment

        • SOR

          #5
          Re: Need help to code collapsing menu

          <comp.lang.ph p , SOR , webmaster@spare sorrepair.co.uk .INVALID>
          <MPG.1d39d3a998 c0deac989c97@no-cancel.newsread er.com>
          <Sat, 9 Jul 2005 13:30:08 +0100>
          [color=blue][color=green]
          > > Could you explain further?, how would I get it to highlite the active link?
          > >[/color]
          >
          > www.snipe.net this guys nav menu uses the sort of thing you want to do -
          > it might be worth a email to ask him for the source code as his method
          > is probably better than mine .
          >[/color]





          Keep in mind i'm a newbie like yourself and this is probably the worse
          way to do it .

          Comment

          • Geoff Berrow

            #6
            Re: Need help to code collapsing menu

            I noticed that Message-ID:
            <MPG.1d39e84d9d e4b21f989c98@no-cancel.newsread er.com> from SOR contained
            the following:
            [color=blue]
            >www.ganjahost.co.uk/rigga[/color]

            doesn't work in FF.
            --
            Geoff Berrow (put thecat out to email)
            It's only Usenet, no one dies.
            My opinions, not the committee's, mine.
            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

            Comment

            • SOR

              #7
              Re: Need help to code collapsing menu

              <comp.lang.ph p , Geoff Berrow , blthecat@ckdog. co.uk>
              <isnvc19ft62rgi c7obbdojl525pve ab070@4ax.com>
              <Sat, 09 Jul 2005 15:30:54 +0100>
              [color=blue][color=green]
              > >www.ganjahost.co.uk/rigga[/color]
              >
              > doesn't work in FF.
              >[/color]

              Then try it at normal speed :-))

              Comment

              • rigga

                #8
                Re: Need help to code collapsing menu

                On Sat, 09 Jul 2005 15:32:33 +0100, SOR wrote:
                [color=blue]
                > <comp.lang.ph p , Geoff Berrow , blthecat@ckdog. co.uk>
                > <isnvc19ft62rgi c7obbdojl525pve ab070@4ax.com>
                > <Sat, 09 Jul 2005 15:30:54 +0100>
                >[color=green][color=darkred]
                >> >www.ganjahost.co.uk/rigga[/color]
                >>
                >> doesn't work in FF.
                >>[/color]
                >
                > Then try it at normal speed :-))[/color]
                Thank you thats exactly what I was trying to achieve, I will look over the
                code and see if I understand it. Like Geoff said it doesn't work in
                Firefox though, but I will look in to that.

                I really appreciate you taking the time to help me with this.

                all the best



                Comment

                • SOR

                  #9
                  Re: Need help to code collapsing menu

                  <comp.lang.ph p , rigga , rigga@hasnomail .com>
                  <pan.2005.07.09 .20.31.31.83367 8@hasnomail.com >
                  <Sat, 09 Jul 2005 21:31:34 +0100>
                  [color=blue]
                  > Like Geoff said it doesn't work in
                  > Firefox though, but I will look in to that.
                  >[/color]

                  Putting a <br> at the end of the <a> tags would probably sort it .

                  Fartfox often screws things up :-)

                  Comment

                  • SOR

                    #10
                    Re: Need help to code collapsing menu

                    <comp.lang.ph p , SOR , webmaster@spare sorrepair.co.uk .INVALID>
                    <MPG.1d3a75a682 0436be989ca7@no-cancel.newsread er.com>
                    <Sun, 10 Jul 2005 01:06:53 +0100>
                    [color=blue]
                    > Putting a <br> at the end of the <a> tags would probably sort it .
                    >[/color]

                    Either way the following is probably a better way of doing it as it does
                    away with 2 include files .


                    inc_nav.php

                    <?php $rigga = $_GET['pass']; ?>

                    <a href="index.php " class="butnav"> HOME</a><br>
                    <a href="group_one .php?pass=1" class="butnav"> GROUP ONE</a><br>
                    <?php if ($rigga==1) {g_one();} ?>
                    <a href="group_two .php?pass=2" class="butnav"> GROUP TWO</a><br>
                    <?php if ($rigga==2) {g_two();} ?>
                    <a href="index.php " class="butnav"> HOME</a><br>

                    <?php
                    function g_one()
                    {
                    print "<a href=index.php? pass=1 class=butnav>.. ... GROUP ONE</a><br>";
                    print "<a href=index.php? pass=1 class=butnav>.. ... GROUP ONE</a><br>";
                    }
                    ?>

                    <?php
                    function g_two()
                    {
                    print "<a href=index.php? pass=2 class=butnav>.. ... GROUP TWO</a><br>";
                    print "<a href=index.php? pass=2 class=butnav>.. ... GROUP TWO</a><br>";
                    }
                    ?>

                    Comment

                    • SOR

                      #11
                      Re: Need help to code collapsing menu

                      <comp.lang.ph p , SOR , webmaster@spare sorrepair.co.uk .INVALID>
                      <MPG.1d3b4a436d 51d1a8989cab@no-cancel.newsread er.com>
                      <Sun, 10 Jul 2005 16:08:21 +0100>
                      [color=blue]
                      > inc_nav.php
                      >[/color]

                      Being a newbie I was curious how to do it without using stuff like
                      ?pass=1 in the url and came up with this .

                      Do a cut-n-paste into inc_nav.php

                      <?php $filename=$_SER VER["REQUEST_UR I"]; ?>

                      <a href="index.php " class="butnav"> HOME</a><br>
                      <a href="group_one .php" class="butnav"> GROUP ONE</a><br>
                      <?php if ($filename=="/rigged/group_one.php") {g_one();} ?>
                      <a href="group_two .php" class="butnav"> GROUP TWO</a><br>
                      <?php if ($filename=="/rigged/group_two.php") {g_two();} ?>
                      <a href="index.php " class="butnav"> HOME</a><br>

                      <?php
                      function g_one()
                      {
                      print "<a href=index.php class=butnav>.. ... GROUP ONE</a><br>";
                      print "<a href=index.php class=butnav>.. ... GROUP ONE</a><br>";
                      }
                      ?>

                      <?php
                      function g_two()
                      {
                      print "<a href=index.php class=butnav>.. ... GROUP TWO</a><br>";
                      print "<a href=index.php class=butnav>.. ... GROUP TWO</a><br>";
                      }
                      ?>






                      <?php if ($filename=="/rigged/group_one.php") {g_one();} ?>

                      "/rigged/group_one.php"

                      /rigged/ being the folder name i used and you will need to adjust this
                      to suit your own webspace .

                      Comment

                      • SOR

                        #12
                        Re: Need help to code collapsing menu

                        <comp.lang.ph p , SOR , webmaster@spare sorrepair.co.uk .INVALID>
                        <MPG.1d3b7e0020 1d800d989cb6@no-cancel.newsread er.com>
                        <Sun, 10 Jul 2005 19:51:41 +0100>
                        [color=blue]
                        > Being a newbie I was curious how to do it without using stuff like
                        > ?pass=1 in the url and came up with this .
                        >
                        > Do a cut-n-paste into inc_nav.php
                        >
                        > <?php $filename=$_SER VER["REQUEST_UR I"]; ?>
                        >
                        > <a href="index.php " class="butnav"> HOME</a><br>
                        > <a href="group_one .php" class="butnav"> GROUP ONE</a><br>
                        > <?php if ($filename=="/rigged/group_one.php") {g_one();} ?>
                        > <a href="group_two .php" class="butnav"> GROUP TWO</a><br>
                        > <?php if ($filename=="/rigged/group_two.php") {g_two();} ?>
                        > <a href="index.php " class="butnav"> HOME</a><br>
                        >[/color]

                        And perhaps a good reason why you shouldnt listen to a newbie .

                        If you clicked on a sub menu link - the sub menu would disappear .

                        This seems to work quite well though , Thanks for asking the question
                        dude as I learnt loads from doing it .




                        inc_nav.php

                        <?php $filename=$_SER VER["REQUEST_UR I"]; ?>

                        <?php $g1=0; $g2=0; ?>

                        <?php

                        if ($filename=="/rigged/group_one.php") {$g1=1;}
                        if ($filename=="/rigged/anythings.php") {$g1=1;}
                        if ($filename=="/rigged/bigjobbys.php") {$g1=1;}

                        if ($filename=="/rigged/group_two.php") {$g2=1;}
                        if ($filename=="/rigged/blahblahs.php") {$g2=1;}
                        if ($filename=="/rigged/foofoofoo.php") {$g2=1;}

                        ?>

                        <a href="index.php " class="butnav"> HOME</a><br>
                        <a href="group_one .php" class="butnav"> GROUP ONE</a><br>
                        <?php if ($g1==1) {g_one();} ?>
                        <a href="group_two .php" class="butnav"> GROUP TWO</a><br>
                        <?php if ($g2==1) {g_two();} ?>
                        <a href="index.php " class="butnav"> HOME</a><br>

                        <?php
                        function g_one()
                        {
                        print "<a href=index.php class=butnav>.. ... GROUP ONE</a><br>";
                        print "<a href=index.php class=butnav>.. ... GROUP ONE</a><br>";
                        }
                        ?>

                        <?php
                        function g_two()
                        {
                        print "<a href=index.php class=butnav>.. ... GROUP TWO</a><br>";
                        print "<a href=index.php class=butnav>.. ... GROUP TWO</a><br>";
                        }
                        ?>

                        Comment

                        Working...