We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21417
    • 486 Posts
    Howdy,

    How do I get wayfinder to include class="first" as well as "active" and "last"?

    I am using:
    MODx version - 1.0.0
    Version codename - rev 5601
    Wayfinder - 2.0

    [[Wayfinder? &startId=`0` &level=`0` &outerTpl=`menu wrapper` &rowTpl=`menu row` &titleOfLinks=`menutitle` &excludeDocs=`1,8,9,10,11`]]


    <li [+wf.classes+]><a href="[+wf.link+]" title="[+wf.title+]">[+wf.linktext+]</a></li>


    I’d like it to look like this, rather than having to do [+wf.docid+] (code bloat for a simple list) to hide a background image on the first element - and what if the menu order changes, and the existing first element is moved??

    <ul>
     <li class="first"><a href="#" title="blah">Blah</a></li>
     <li><a href="#" title="blah">Blah</a></li>
     <li class="active"><a href="#" title="blah">Blah</a></li>
     <li><a href="#" title="blah">Blah</a></li>
     <li><a href="#" title="blah">Blah</a></li>
     <li class="last"><a href="#" title="blah">Blah</a></li>
    </ul>


    Thanks in advance.
      Web design Adelaide
      http://gocreate.com.au
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      &firstClass=`first`
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 21417
        • 486 Posts
        sweet - thanks Sottwell.
        That does the trick!
          Web design Adelaide
          http://gocreate.com.au
          • 6659
          • 18 Posts
          Apologies for the bump - this topic appears high in Google results for searches for the issue I’ve had which I’ve now resolved, so I thought I’d post the fix here.

          The problem I had was that the "last" class wasn’t being applied to the first element in a wayfinder submenu. The "first" class was being applied, but I wanted both. I fixed this by changing line 93 of assets/snippets/wayfinder/wayfinder.inc.php from this:

          if ($counter == ($numSubItems) && $numSubItems > 1) {


          To this:

          if ($counter == ($numSubItems) && $numSubItems >= 1) {


          The "last" class isn’t applied to the last element if there’s only one element in the list.
            • 21417
            • 486 Posts
            awesome - thanks for the heads up DaveChild
              Web design Adelaide
              http://gocreate.com.au
              • 36805
              • 354 Posts
              I also ran into this issue. The fix worked fine. I filed a bug report at bugs.modxcms.com (as an Evolution issue). I’d guess Revo has the same issue though, but I don’t use it.
                • 15001
                • 697 Posts
                Solved issue :

                firstClass and lastClass do not seem working when using a configuration :
                [!Wayfinder? &startId=`13` &config=`menu_horizontal` !]

                I tried adding &lastClass=`last` to the snippet call,
                and also putting $lastClass='last'; to the config file.
                None worked.

                (skipped)

                Solution: Don't forget inserting a [+wf.classes+] placeholder in the (X)HTML element where you want the class="your_firstClass" class="your_lastClass" to be printed.
                [ed. note: Jul last edited this post 13 years, 11 months ago.]
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  What does the menu_horizontal config code look like?
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 15001
                    • 697 Posts
                    Thank you Susan. I had forgotten to put a [+wf.classes+]. Your question helped me to look in the right direction. I edited my previous post.