Keep the Page Links on Top Menu Bar Instead of Displaying Categories in nopCommerce

Many times when store admin installs the nopCommerce out of the box and start adding the categories for products they realize that suddenly the page links on top menu disappears (like homepage, my account, contact us etc) and only the product categories shows up.

Well, this change is due to one of the condition that is hard-coded in the top menu bar section of nopCommerce.

Many store owners prefer to display the page links on the top menu bar instead of categories and this quick tip tutorial is for all those store admins who wish to keep the page links in the menu (instead of categories).

In your code, go to: Presentation/Nop.Web > Views > Catalog > TopMenu.cshtml

Open the page “TopMenu.cshtml”

In the code you will see this:

<ul class="top-menu">
    @if (Model.Categories.Count > 0)
        foreach (var category in Model.Categories)
            @RenderCategoryLine(category, 0, false)
        //no categories to display? in this case let's diplay some default menu items (should we?)
        <li><a href="@Url.RouteUrl("HomePage")">@T("HomePage")</a></li>
        if (Model.RecentlyAddedProductsEnabled)
            <li><a href="@Url.RouteUrl("RecentlyAddedProducts")">@T("Products.NewProducts")</a>
        <li><a href="@Url.RouteUrl("ProductSearch")">@T("Search")</a> </li>
        <li><a href="@Url.RouteUrl("CustomerInfo")">@T("Account.MyAccount")</a></li>
        if (Model.BlogEnabled)
            <li><a href="@Url.RouteUrl("Blog")">@T("Blog")</a></li>
        if (Model.ForumEnabled)
            <li><a href="@Url.RouteUrl("Boards")">@T("Forum.Forums")</a></li>
        <li><a href="@Url.RouteUrl("ContactUs")">@T("ContactUs")</a></li>

If you pay attention so the code, at the beginning you will find the IF CONDITION that states that if categories is more than 1 then display the categories. This is the reason your top menu only shows categories because the code is forcing the site to display categories only.

Now, if we update this:

@if (Model.Categories.Count > 0)

to this:

@if (Model.Categories.Count == 0)

This should make the top menu to display only the page links and not categories. Why? Because we have change the condition by simply using “==” (NOT EQUAL SIGN). According to the new condition, if category is not equal to 0 (which can be anything more than 0 like 1 or 2 or any number), the code will perform the task mention in the “ELSE” case i.e. display the menu links.

Looking for quality nopCommerce Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , , , | Posted under nopCommerce | RSS 2.0

Author Spotlight

Lavish Kumar

Founder, developer and owner of - By profession, he is a software programmer / web developer, web designer & DBA. He is passionate about technology and electronic gadgets. He enjoys writing tech articles and developing web applications. He is a nopCommerce MVP and author of official nopCommerce Designer's Guide.

Leave a Reply

Your email address will not be published. Required fields are marked *