We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29288
    • 13 Posts
    So, Last night i started to convert my design for a client over to MODx, it’s a simple little Foxy Cart Boutique store with only about 6 products - perfect for Foxycart and MODx. They wanted to originally go with Monster, but i was able to convince them otherwise. So first things first was setting up the Navigation.

    The Single Image Rollover effect i’ve been using for these situations can be found here:
    http://ghettocooler.net/2007/05/31/simple-navigation-with-css-image-replacement/

    With only a minimal amount of modding i was able to get this up and working in MODx.

    1. replacing my hardcoded navigation with Wayfinder

    REPLACE THIS:
    <div id="nav">
          <ul id="navigation">
            <li id="nav1"><a href="belts/" >Belts</a></li>
            <li id="nav2"><a href="jewelry/">Jewelry</a></li>
            <li id="nav3"><a href="contact/">Contact</a></li>
            <li id="nav4"><a href="about/">About</a></li>
            <li id="nav5"><a href="retailers/">Retailers</a></li>
            <li id="nav6"><a href="wholesale/">Wholesale</a></li>
         </ul>
        </div>


    WITH THIS:
    <ul id="navigation">
         [!Wayfinder?startId=`0`&level=`1` &rowIdPrefix=`navitem`!]     
         </ul>
    


    I’m using the &level 1 as there are subpages for a few categories that i don’t want to appear in the navigation. and rowIdPrefix to give each list item it’s own specific id. This is nessessary for the single image navigation to function. Since i set the rowIdPrefix to be "navitem" the generated nav sans CSS will look something like this:

    <div id="nav">
         <ul id="navigation">
            <ul>
                <li id="navitem2" class="active"><a href="/index.php?id=2" title="Belts" >Belts</a></li>
                <li id="navitem3"><a href="/index.php?id=3" title="Jewelry" >Jewelry</a></li>
                <li id="navitem4"><a href="/index.php?id=4" title="Contact" >Contact</a></li>
                <li id="navitem5"><a href="/index.php?id=5" title="About" >About</a></li>
                <li id="navitem6"><a href="/index.php?id=6" title="Retailers" >Retailers</a></li>
                <li id="navitem7" class="last"><a href="/index.php?id=7" title="Wholesale" >Wholesale</a></li>
           </ul>     
    </ul>
    </div>
    


    Now if you followed the ghetto cooler tutorial at the top of the page, you should have your single nav image and your CSS, just make sure your CSS nav item ID’s reflect the IDs you setup through wayfinder and you should be well on your way to a nice little single image nav using wayfinder. Of course, if you add any new navigation through MODx you’ll need to rework your navigation image and CSS.

    The Last thing to do is to get your navigation to stay active on your active pages. This is difficult using the single image effect because just one CSS class like .active won’t do the trick since we’re using background-position to create the rollover effect and each nav item uses a specific bg-position.

    What i decided to do was to use the suggestion @ ghetto cooler; to give each pages body a custom id, and use that as a CSS selector - but to do this, without having to handcode each page was to use MODx’s internal template code to generate my page Ids - in my case, since the nav items, for instance "Belts" had multiple pages under them i needed an id that multiple pages could share, so i couldn’t use the PAGETITLE, i instead used the alias, as multiple pages seem to be able to share the same alias. my template code looks like this:

    <body id="[*alias*]">


    and my new rollover and active css looks like this:

    ul li#navitem2 a:hover, body#Belts ul li#navitem2 a{
    background-position: XXpx -XXpx;
     }


    Once that’s all in place, and MODx replaces the template code with the page alias (in this case, Belts) you should have a perfectly nice single image rollover navigation tied to your MODx backend. Enjoy.

    ps. I’m rather new to Working with MODx and i’ve gotten great help from everyone here. I know this tutorial probably isn’t the best and only way to do it, and i hope some of you will explain even better methods or if this wasn’t clear enough, ask questions. But i wanted to give a little something back. Enjoy.

    -T





      • 7231
      • 4,205 Posts
      Nice tutorial. Thanks for posting it grin grin
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 16183
        • 1,390 Posts
        Thanks T for this tut. Very well written!

        I have two observations:

        <ul id="navigation">
             [!Wayfinder?startId=`0`&level=`1` &rowIdPrefix=`navitem`!]     
             </ul>



        1. In the code above, why do you need to place the Wayfinder call inside the <ul>? I ask since the menu WF will generate will also have <ul> tags in its outermost container. You probably did this since you wanted to give the ul an id? You might as well have done this in the outerTpl, e.g.

        <ul id="navigation"[+wf.classes+]>
        	[+wf.wrapper+]
        </ul>


        I might be missing something here. My point is that you end up with a extra <ul> tags you probably don’t need?

        2. Secondly - the trick of giving the body tags of your documents an id. I am wondering if this could not be achieved dynamically using WF alone. It seems the ghetto...tut applies to static pages in this respect?

        WF offers several classes to denote the active document. E.g. if I am not mistaken, WF will automatically give the active document a class "active". There’s also the "selfClass". I could be wrong here. But the advantage I see here is that using the WF method, you would only have one CSS declaration to style all documents whenever they are active instead of having CSS hover and active rules for each and every document in your menu.

        I probably don’t get it so I might be wrong.  ;D

        EDIT #1: I have re-read my second observation above and I have a feeling I am wrong...lemme read it one more time wink

        EDIT #2: Ignore the second comment above - I wasn’t getting it grin

        EDIT #3: Seems I was right after all. See the post below. We can take advantage of Wayfinder’s dynamically generated "active" class for documents that are current grin

        Again, very good effort! Thx for sharing...

        cheers/k

          • 29288
          • 13 Posts
          Kongondo - You’re right about the unnecessary UL, i wasn’t feeling like figuring out how to setup my wf.class and wf.wrapper info last night so i just did what worked - but you’re right, it makes sense to eliminate the unnecessary UL. tks for the heads up. cool

          I’m interested to hear if someone else has an idea on how to select the pages for active linking.
            • 16183
            • 1,390 Posts
            OK,

            Seems I was right after all - about my second comment above - regarding the use of WF’s dynamically generated "active" class.

            I managed to make this work, without using the body tags, i.e.

            <body id="[*alias*]">


            Like I said above, Wayfinder will automatically create an "active" class for any list/menu item that is currently being viewed. In addition, since we are using the &rowIdPrefix we have two selectors we can use. The id and the dynamic active class of the menu items. Armed with this info, for each document, I just added identical CSS rules to the "active" class and the a:hover like you did with the body tag. Here’s a sample CSS code

            div#navigation ul li#nav71 a:hover, div#navigation ul li#nav71.active a{
            background-position:-164px -80px


            In the above example my &rowIdPrefix=`nav` in my Wayfinder call

            The end result was a CSS sprite menu with the "persistent" hover state

            Like they say (OK, I know, cliche) - "there’s usually more than one way to something in modx" wink

            Thanks again for this Tut T.

            cheers/k



              • 29288
              • 13 Posts
              Fantastic - nice job, i’ll be sure to use this in the future. Q: For my current setup, which has sub pages that aren’t navigable through the main nav, but that i still need to keep the parent nav menu item highlighted - i’d have to add css values for every subpage, it could just be apples to oranges, but for situation it seems more efficient to give the bodies of parent and children the same ID value ( the alias ) - or am i way off base smiley

              Thanks again for taking a look - the more i use MODx the more i really dig it.
                • 4429
                • 429 Posts
                Must of missed a trick here as I dont have it working.


                CSS
                	ul#nav {	
                		width:225px;
                		list-style:none;
                		height:620px;
                		float: left;
                			}
                
                	ul#nav li {
                		display:block;
                		text-indent:-9999px;
                		text-decoration:none
                	}
                
                	ul#nav li a {
                		width:225px;
                		display:block
                	}
                
                	ul#nav  li a span {
                		float:left;
                		display:block
                	}
                
                	ul#nav li#nav-1 a {
                		height:50px;
                		background:url(../images/nav1.jpg) no-repeat 0 0px
                	}
                
                	ul#nav li#nav-1 a:active,
                	ul#nav li#nav-1 a:hover {
                		background-position: -225px 0px
                	}
                
                	ul#nav li#nav-2 a {
                		height:50px;
                		background:url(../images/nav1.jpg) no-repeat 0 -50px
                	}
                
                	ul#nav li#nav-2 a:active,
                	ul#nav li#nav-2 a:hover {
                		background-position: -225px -50px
                	}
                
                	ul#nav li#nav-3 a {
                		height:50px;
                		background:url(../images/nav1.jpg) no-repeat 0 -100px
                	}
                
                	ul#nav li#nav-3 a:active,
                	ul#nav li#nav-3 a:hover {
                		background-position: -225px -100px
                	}
                
                	ul#nav li#nav-4 a {
                		height:50px;
                		background:url(../images/nav1.jpg) no-repeat 0 -150px
                	}
                
                	ul#nav li#nav-4 a:active,
                	ul#nav li#nav-4 a:hover {
                		background-position: -225px -150px
                	}
                
                	ul#nav li#nav-5 a {
                		height:50px;
                		background:url(../images/nav1.jpg) no-repeat 0 -200px
                	}
                
                	ul#nav li#nav-5 a:active,
                	ul#nav li#nav-5 a:hover {
                		background-position: -225px -200px
                	}
                


                HTML - navigation chunk
                		<li id="nav-1"><a href="#" title="HOME"><span>HOME</span></a></li>
                		<li id="nav-2"><a href="#" title="ABOUT US"><span>ABOUT US</span></a></li>
                		<li id="nav-3"><a href="#" title="SERVICES"><span>SERVICES</span></a></li>
                		<li id="nav-4"><a href="#" title="RECRUITMENT"><span>RECRUITMENT</span></a></li>
                		<li id="nav-5"><a href="#" title="CONTACT US"><span>CONTACT US</span></a></li>


                Wayfinder call
                <ul id="nav">
                
                 [!Wayfinder?startId=`0`&rowIdPrefix=`navigation`!]  
                
                  </ul>


                The site is a development site at http://www.presspointproofing.co.uk/easton
                  • 18374
                  • 69 Posts
                  @c-m

                  Why the extra <span> in your links? You could probably yank that entirely and accomplish the same result using just the <li> and <a>.

                  Make sure you give both the <li> and <a> a height. Here’s my similar CSS from another project:

                  ul#primary-nav li {
                  	float: left;
                  	text-indent: -1000em;
                  	background-position: 0 0;
                  	background-repeat: no-repeat;
                  }
                  
                  ul#primary-nav li, ul#primary-nav a {
                  	display: block;
                  	height: 26px;
                  }
                  
                  ul#primary-nav a:hover {
                  	background-position: 0 -26px;
                  }
                  
                  li#primary-nav-2 a {
                  	width: 102px;
                  	background-image: url("../images/site/nav/nav_about-us.png");
                  }
                  
                  //rest of primary-nav-# a
                    • 4429
                    • 429 Posts
                    Thanks,

                    I have removed the span tags and added image heights but my background is not displaying at all:

                    Here is the CSS

                    html, body {
                    	margin: 0;
                    	padding: 0;
                    }
                    
                    body {
                    	font-family: Verdana, Arial, Helvetica, sans-serif;
                    	font-size: 10px;
                    	color: #000000;
                    	background: #d5d5d5;
                    }
                    
                    
                    #page-container {
                    	width: 960px;
                    	margin: 0px auto;
                    	background-color:#ffffff;
                    }
                    
                    
                    
                    /****** layout columns ******/
                    
                    #header {
                    	height: 200px;
                    	width: 960px;
                    	background: #ffffff	url(../images/header.jpg) no-repeat;
                    }
                    	
                    	
                    
                    
                    
                    
                    
                    /* VERTICAL NAVIGATION BAR
                    	/////////////////////////////////////*/
                    
                    
                    	ul#nav {	
                    		width:225px;
                    		list-style:none;
                    		height:620px;
                    		float: left;
                    					}
                    
                    	ul#nav li {
                    		display:block;
                    		text-decoration:none;
                    		height: 50px;
                    	}
                    
                    	ul#nav li a  {
                    width : 225px;
                    display : block;
                    height : 50px;
                    text-decoration : none;
                    } 
                    
                    	
                    	ul#nav li#nav-1 a {
                    		height:50px;
                    		background:url(../images/nav1.jpg) no-repeat 0 0px
                    	}
                    
                    	ul#nav li#nav-1 a:active,
                    	ul#nav li#nav-1 a:hover {
                    		background-position: -225px 0px
                    	}
                    
                    	ul#nav li#nav-2 a {
                    		height:50px;
                    		background:url(../images/nav1.jpg) no-repeat 0 -50px
                    	}
                    
                    	ul#nav li#nav-2 a:active,
                    	ul#nav li#nav-2 a:hover {
                    		background-position: -225px -50px
                    	}
                    
                    	ul#nav li#nav-3 a {
                    		height:50px;
                    		background:url(../images/nav1.jpg) no-repeat 0 -100px
                    	}
                    
                    	ul#nav li#nav-3 a:active,
                    	ul#nav li#nav-3 a:hover {
                    		background-position: -225px -100px
                    	}
                    
                    	ul#nav li#nav-4 a {
                    		height:50px;
                    		background:url(../images/nav1.jpg) no-repeat 0 -150px
                    	}
                    
                    	ul#nav li#nav-4 a:active,
                    	ul#nav li#nav-4 a:hover {
                    		background-position: -225px -150px
                    	}
                    
                    	ul#nav li#nav-5 a {
                    		height:50px;
                    		background:url(../images/nav1.jpg) no-repeat 0 -200px
                    	}
                    
                    	ul#nav li#nav-5 a:active,
                    	ul#nav li#nav-5 a:hover {
                    		background-position: -225px -200px
                    	}
                    
                    
                    
                    #sidebar {
                    	height: 470px;
                    	width: 230px;
                    	float: right;
                    	margin: 50px 50px 50px 25px;
                    }
                    
                    
                    #content {
                    	height: 570px;
                    	width: 400px;
                    	line-height: 18px;
                    	margin-left: 225px;
                    	margin-right: 230px;
                    }
                    
                    	
                    #footer {
                    	height: 42px;
                    	width: 675px;
                    	margin-left: 225px;
                    	margin-right: 50px;
                    	line-height: 18px;
                    	margin-top: 5px;
                    	background: #ffffff;
                    }
                    
                    
                    
                    /******* content styles *******/
                    
                    #content h1 {
                    	margin: 0;
                    	padding: 0;
                    	font-family: Verdana, Arial, Helvetica, sans-serif;
                    	padding-bottom: 15px;
                    	font-weight: 400;
                    	font-size: 22px;
                    	color: #981c1e;
                    }
                    
                    #content h2 {
                    	margin: 0;
                    	padding: 0;
                    	padding-bottom: 15px;
                    	font-family: Verdana, Arial, Helvetica, sans-serif;
                    	font-weight: 300;
                    	font-size: 18px;
                    	color: #981c1e;
                    }
                    
                    #content p {
                    	margin: 0;
                    	padding: 0;
                    	font-family: Verdana, Arial, Helvetica, sans-serif;
                    	font-size: 10px;
                    	color: #000000;
                    }
                    
                    #content a {
                    	margin: 0;
                    	padding: 0;
                    	font-family: Verdana, Arial, Helvetica, sans-serif;
                    	font-size: 12px;
                    	color: #981c1e;
                    	text-decoration: none;
                    }
                    
                    .padding {
                    	padding: 50px 25px 10px 25px;
                    }
                    
                    .footerpadding {
                    	padding: 5px 50px 10px 25px;
                    }


                    The website is here:

                    http://www.presspointproofing.co.uk/easton/
                      • 18374
                      • 69 Posts
                      @c-m

                      Your CSS is targeting an ID of "nav-1" but your source code is showing "navigation1". I made a quick change in Firebug and got your background image to show. Just make sure your image is positioned correctly (it appears to be a set of sprites).

                      You’ll also want to put a negative text-indent on either the a or li element to hide the text.