Thursday, November 4, 2010

Update: Hide First Tab in SP 2010 Navigation

My original article used CSS to hide the first navigation tab, but if you want to make the change via the master page navigation control there are some simple changes that you will need to make. I originally thought by just changing the “ShowStartingNode” property it would simply hide the first node but by default it has it already set to false: ShowStartingNode="False" so the approach below is what worked for me.

Here is the base top navigation control:
<SharePoint:AspMenu
  ID="TopNavigationMenuV4"
  Runat="server"
  EnableViewState="false"
  DataSourceID="topSiteMap"
  AccessKey="<%$Resources:wss,navigation_accesskey%>"
  UseSimpleRendering="true"
  UseSeparateCss="false"
  Orientation="Horizontal"
  StaticDisplayLevels="2"
  MaximumDynamicDisplayLevels="1"
  SkipLinkText=""
  CssClass="s4-tn"/>
<SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource" Id="topNavigationDelegate">
    <Template_Controls>
        <asp:SiteMapDataSource
          ShowStartingNode="False"
          SiteMapProvider="SPNavigationProvider"
          id="topSiteMap"
          runat="server"
          StartingNodeUrl="sid:1002"/>
    </Template_Controls>
</SharePoint:DelegateControl>

image

First off Remove the following:
<SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource" Id="topNavigationDelegate">
    <Template_Controls>
        <asp:SiteMapDataSource
          ShowStartingNode="False"
          SiteMapProvider="SPNavigationProvider"
          id="topSiteMap"
          runat="server"
          StartingNodeUrl="sid:1002"/>
    </Template_Controls>
</SharePoint:DelegateControl>

And then make the following changes to the static, dynamic and site map provider:
<SharePoint:AspMenu
  ID="TopNavigationMenuV4"
  Runat="server"
  EnableViewState="false"
  DataSourceID="topSiteMap"
  AccessKey="<%$Resources:wss,navigation_accesskey%>"
  UseSimpleRendering="true"
  UseSeparateCss="false"
  Orientation="Horizontal"
  StaticDisplayLevels="1"
  MaximumDynamicDisplayLevels="2"
  SkipLinkText=""
  CssClass="s4-tn"/>
        <asp:SiteMapDataSource
          ShowStartingNode="False"
          SiteMapProvider="CombinedNavSiteMapProvider"
          id="topSiteMap"
          runat="server"/>

The result would look something like this:
image

Thanks to c_marius for the comment and jsalazar80016 for the approach.

12 comments:

sukiakisu said...

great post! this would definitely be my first choice for doing this in 2010 so that you can retain the simple rendering. thanks for the tip!

venkata said...

Hi Eric,
I have a quick question, but this is not relevant to this post. How would i automatically inherit a custom masterpage and css to a new subsite created in SharePoint 2010?
Do you have any guidelines for creating a stapling feature which forces the custom masterpage to be used in all new subsites created.
I am aware of the changesitemasterpage.aspx in the root site to force the settings but i am looking for an automatic process. I appreciate any help on this one.
BTW , i am a regular follower of your posts ..
Love your work.
Venkat

Abul Khalam Azad said...

is three level navigation is posible

Anonymous said...

Great Article!

Thanks a lot.

ljcmaster said...

Hi Eric,
Great Post, Very Usefull.
I have a question. I created a dropdown menu by following this post, but only 20 submenu appear in the menu on my site and in my site there are 22 subsites.
Any ideas?
Please help me.

eduferreira said...

To hide by CSS:

div.menu-horizontal > ul.static > li.static > a { display:none !important;}

Lodlaiden said...

This method works, but any items that are hidden through the _layouts/AreaNavigationSettings.aspx page will be shown.

Anonymous said...

Very useful post!! I tried various solutions but in vain however this one is the master piece!!!
Thanks a lot!

Søren Juul Rasmussen said...

Just what I needed - thanks

Anonymous said...

Hi!
There is a mistake in your post: StartingNodeUrl="sid:1002"/> should not be removed, right?

I am also working with a problem that all items (libraries etc.) comes under top level navigation after this change. What should I do if I want only sites and pages to appear on top level navigation?

Maulee Vadi said...

I tried the master page change and it works but my Welcome Page URL is still pointing to default.aspx page and so when I just type URL for my site, it defaults to Default.aspx page which I don’t want.. and if I change the Welcome page URL, my first tab is hidden but now 2nd tab gets hidden too..

Any help will be appreciated.

viji said...

Hi,
Did anyone find a solution to hide all items (libraries etc.) comes under top level navigation after this change. I need to display only sites and pages to appear on top level navigation