Cateogry Menu in HeaderMenu

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Hi Everyone,

I am working on a website and want to add the Category menu to the top menu bar and also have it on the side. Is this possible. How do I do it.

Thanks,

Kimber
13 years ago
Hello.

In the modules folder locate headermenu.ascx and add this to the end of the <ul> list

<li><a href="<%=Page.ResolveUrl("~/Categories.aspx")%>">
            <span><%=GetLocaleResourceString("Category.Categories")%></span></a>
</li>


Then you will need to create a categories page. Copy the Manufacturers.aspx page and rename it to Categories.aspx. change file Categories.aspx.cs to:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NopSolutions.NopCommerce.BusinessLogic.Categories;
using NopSolutions.NopCommerce.BusinessLogic.SEO;
using NopSolutions.NopCommerce.BusinessLogic.Media;
using NopSolutions.NopCommerce.BusinessLogic.Configuration.Settings;

namespace NopSolutions.NopCommerce.Web
{
    public partial class CategoriesPage : BaseNopPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SEOHelper.RenderTitle(this, GetLocaleResourceString("PageTitle.Categories"), true);
        }

        
    }
}


and file Categories.aspx to:

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPages/ThreeColumn.master"
    CodeBehind="Categories.aspx.cs" Inherits="NopSolutions.NopCommerce.Web.CategoriesPage" %>

<%@ Register TagPrefix="nopCommerce" TagName="HomePageCategoriesHack" Src="~/Modules/HomePageCategoriesHack.ascx" %>
<asp:Content runat="server" ContentPlaceHolderID="cph1">
    <div class="manufacturerlist-page">
        <div class="page-title">
            <h1>
                <%=GetLocaleResourceString("Category.Categories")%></h1>
        </div>
        <div class="clear">
        </div>
        <nopCommerce:HomePageCategoriesHack ID="ctrlHomePageCategories" runat="server" />
    </div>
</asp:Content>


Now back to the modules folder copy HomePageCategories.ascx to HomePageCategoriesHack.ascx
change the HomePageCategoriesHack.ascx.cs to:

namespace NopSolutions.NopCommerce.Web.Modules
{
    public partial class HomePageCategoriesHack : BaseNopUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        protected void BindData()
        {
            var subCategoryCollection = CategoryManager.GetAllCategories(0);
            if (subCategoryCollection.Count > 0)
            {
                dlCategories.DataSource = subCategoryCollection;
                dlCategories.DataBind();
            }
            else
                this.Visible = false;
        }

        protected void dlCategories_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var category = e.Item.DataItem as Category;
                var hlImageLink = e.Item.FindControl("hlImageLink") as HyperLink;
                string categoryURL = SEOHelper.GetCategoryUrl(category.CategoryId);
                if (hlImageLink != null)
                {
                    hlImageLink.ImageUrl = PictureManager.GetPictureUrl(category.PictureId, SettingManager.GetSettingValueInteger("Media.Category.ThumbnailImageSize", 125), true);
                    hlImageLink.NavigateUrl = categoryURL;
                    hlImageLink.ToolTip = String.Format(GetLocaleResourceString("Media.Category.ImageLinkTitleFormat"), category.Name);
                    hlImageLink.Text = String.Format(GetLocaleResourceString("Media.Category.ImageAlternateTextFormat"), category.Name);
                }
              
                HyperLink hlCategory = e.Item.FindControl("hlCategory") as HyperLink;
                if (hlCategory != null)
                {
                    hlCategory.NavigateUrl = categoryURL;
                }
            }
        }
    }
}


Compile and upload the changed files plus NopCommerceStore.dll and NopCommerceStore.pdb that are in the bin folder.
13 years ago
Thanks for your reply.

I must be doing something wrong. I'm new to this. I'm getting the following error.

Server Error in '/' Application.
--------------------------------------------------------------------------------

Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'NopSolutions.NopCommerce.Web.CategoriesPage'.

Source Error:


Line 1:  <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPages/ThreeColumn.master"    
Line 2:      CodeBehind="Categories.aspx.cs" Inherits="NopSolutions.NopCommerce.Web.CategoriesPage" %>
Line 3:      


Source File: /Categories.aspx    Line: 1


Thanks,

Kimber
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.