How To Create a Category Based Navigation Like Lithosphere
A number of communities have implemented navigation similar to what we have on the Lithosphere with tabs across the top that help the user quickly find the major areas of the community. This is a simple example of how that navigation is created. In this example, each tab is a category at the top level of the community. The tabs themselves are hard coded links to each category - Learn, Share, and Help.
First you need to create a custom component in Studio. You will need to have a small amout of freemarker logic for this implementation so a custom content area will not work.
Once you have the component, you must write the basic structure of your tabs.
<ul class="custom-nav-wrapper"> <li class="nav-learn"> <a href="link to learn"><span>Learn</span></a> </li> <li class="nav-share"> <a href="link to share"><span>Share</span></a> </li> <li class="nav-help"> <a href="link to help"><span>Help</span></a> </li> </ul>
This is fairly simple html but you will need to add css to your skin to style it as you like.
Next, you need to account for the active state of each tab. Whenever the user is in a board or thread within that category, the tab should remain highlighted. This requires a little css to be added to the page. For this example we will simply bold the text if the tab is active. You can, of course, add any css here that you would like. The Lithosphere switches out images to highlight the active area.
This code should be placed above the html at the top of your component
<#assign ancestors = coreNode.ancestors?reverse /> <#assign parent= "" > <#if ancestors?size gt 1 > <#assign parent=ancestors[1].id> </#if> <#if parent == "Learn" || coreNode.id == "Learn"> <style> .nav-learn { text-weight:bold; } </style> <#elseif parent == "Share" || coreNode.id == "Share"> <style> .nav-share { text-weight:bold; } </style> <#elseif parent == "Help" || coreNode.id == "Help"> <style> .nav-help{ text-weight:bold; } </style> </#if>
The first part gets a sequence of all the nodes from the current page back up to the top of the community, then reverses it so that community is the first item, ancestors[0]. Since what we want to know is the top category, we set a variable (parent) to the second item in the sequence, ancestors[1]. The second part of our code runs through an if statement of all the top level categories and adds a little bit of css for the correct tab based on which category matches the one in our variable.
And that's just about it... of course you can get a lot fancier by having dynamically built navigation. For that solution you will need to use REST calls to dyamically get all the top level categories and use that info to build your classes and styles. However, if you don't plan to add categories regularly or if you want to choose only some of your categories to be displayed in the navigation, this will work just fine.