We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31850
    • 2 Posts
    I’m trying to get the class of a ul based menu to change according to what page is being viewed. Here is what I have so far:

    In a separate file (nav.php)
    <div id="menu">
    <ul id="menu_ul"
      <li<?php if ($thisPage=="home") 
          echo " class=\"current_page_item\""; ?>><a title="Home" href="index.php">Home</a> </li>
      <li<?php if ($thisPage=="about") 
          echo " class=\"current_page_item\""; ?>><a title="About Us" href="about.html">About</a> </li>
      <li<?php if ($thisPage=="contact") 
          echo " class=\"current_page_item\""; ?>><a title="Contact" href="index.php?id=6">Contact</a> </li>
      <li><a title="View upcoming events" href="/forum/index.php?action=calendar">Calender</a></li>
    	<li><a title="Hang out in the forums" href="/forum">Forums</a>
      </li>
    </ul>
    </div>
    


    Then I use a snippet to include nav.php in the template

    Now the problem I am having is in order to make the $thisPage call work each page has to have the following code at the top so it is parsed before the page loads

    <?php $thisPage="home"; ?>
    (or replace home with whatever the page name is)

    I tried using that as a snippet and just put it on each page right before the content...but it doesn’t parse it before the page loads. Any help would be greatly appreciated.

    I also wanted to add that the nav.php loads correctly, but it doesn’t change the class of the li to reflect the current page.
      • 7455
      • 2,204 Posts
      why not use Wayfinder? all the options are in there.
        follow me on twitter: @dimmy01
        • 31850
        • 2 Posts
        now that i feel like an asshat grin , could you point me in the right direction to setting that up?
        • You can find everything you need right here: http://modxcms.com/forums/index.php/topic,34176.0.html

          We all had to start somewhere so don’t worry about missing that one wink
            Patrick | Server Wrangler
            About Me: Website | TweetsMODX Hosting