Categories Page

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
I've created a new categories page to replace the standard menu option for category navigation, which was simple enough using the manufacturers page as a template.

I want to stop sub-categories showing on this page though, I know how to do this in the menu but is there a simple way to show only the top level categories on the page ?

I also want this new categories page to show in the breadcrumb trail after home(top).

Any ideas ?
12 years ago
You need to uncoment this lines in "ProductsInGrid.ascx" or whatever template file you are used.


<div class="sub-category-grid">
        <asp:DataList ID="dlSubCategories" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"
            RepeatLayout="Table" OnItemDataBound="dlSubCategories_ItemDataBound" ItemStyle-CssClass="item-box">
            <ItemTemplate>
                <div class="sub-category-item">
                    <h2 class="category-title">
                        <asp:HyperLink ID="hlCategory" runat="server" />
                    </h2>
                    <div class="picture">
                        <asp:HyperLink ID="hlImageLink" runat="server" />
                    </div>
                </div>
            </ItemTemplate>
        </asp:DataList>
    </div>
12 years ago
Thanks for the quick answer but I have created a new page a level up from that (same as the manufacturers page from the View All link) and used this code in the .ascx page:

<asp:DataList ID="dlCategories" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"
                RepeatLayout="Table" OnItemDataBound="DlCategories_OnItemDataBound" ItemStyle-CssClass="item-box">
                <ItemTemplate>
                    <div class="manufacturer-item">
                        <h2 class="man-title">
                            <asp:HyperLink ID="hlCategory" runat="server" />
                        </h2>
                        <div class="picture">
                            <asp:HyperLink ID="hlImageLink" runat="server" />
                        </div>
                    </div>
                </ItemTemplate>


And this code in the .cs page:

namespace NopSolutions.NopCommerce.Web
{
    public partial class CategoriesPage : BaseNopFrontendPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SEOHelper.RenderTitle(this, GetLocaleResourceString("PageTitle.Categories"), true);
            if (!IsPostBack)
            {
                dlCategories.DataSource = this.CategoryService.GetAllCategories();
                dlCategories.DataBind();
            }
        }

        protected void DlCategories_OnItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var category = e.Item.DataItem as Category;
                string categoryURL = SEOHelper.GetCategoryUrl(category);

                var hlImageLink = e.Item.FindControl("hlImageLink") as HyperLink;
                if (hlImageLink != null)
                {
                    hlImageLink.ImageUrl = this.PictureService.GetPictureUrl(category.PictureId, this.SettingManager.GetSettingValueInteger("Media.Category.ThumbnailImageSize", 125), true);
                    hlImageLink.NavigateUrl = categoryURL;
                    hlImageLink.ToolTip = String.Format(GetLocaleResourceString("Media.Manufacturer.ImageLinkTitleFormat"), category.LocalizedName);
                    hlImageLink.Text = String.Format(GetLocaleResourceString("Media.Manufacturer.ImageAlternateTextFormat"),category.LocalizedName);
                }

                var hlCategory = e.Item.FindControl("hlCategory") as HyperLink;
                if (hlCategory != null)
                {
                    hlCategory.NavigateUrl =categoryURL;
                    hlCategory.ToolTip = String.Format(GetLocaleResourceString("Media.Manufacturer.ImageLinkTitleFormat"), category.LocalizedName);
                    hlCategory.Text = Server.HtmlEncode(category.LocalizedName);
                }


I haven't changed the manufacturer in the imagelink resources yet.

Was thinking there is a way to get only the top level categories into the databind but not sure how ?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.