Page 1 of 1

Site Map Page for Users on Storefront

Posted: Wed Sep 17, 2008 11:34 am
by ajasko
I would like to have a viewable sitemap on my storefront that has links to all the major pages on my site (main pages, categories, subcategories). This is useful for users to navigate, and search engines like it as well, as it boosts the internal linking scheme of a site. The preferable name would be "sitemap.aspx." The sitemap mxl generator is nice and great for search engine submission, but a viewable sitemap webpage is equally useful, if not more so.

Re: Site Map Page for Users on Storefront

Posted: Wed Sep 17, 2008 11:54 am
by heinscott
Here's a CONLIB I made to recursively build all Categories, with Children underneath. I have each level getting smaller, so, if they are nested too far, you might have some readability issues. This would be something to start from...

Sitemap.ascx

Code: Select all

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SiteMap.ascx.cs" Inherits="ConLib_SiteMap" %>
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %>

<ajax:UpdatePanel ID="DescriptionAjax" runat="server">
    <ContentTemplate>
        <div class="content">
            <table width="100%" cellspacing=0 cellpadding=0>
                <tr>
                    <td>
                       <span class="CategoryHeader">SiteMap</span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <br />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Literal ID="CategoryLinks" runat="server"></asp:Literal>
                    </td>
                </tr>     
            </table>
        </div>
    </ContentTemplate>
</ajax:UpdatePanel>
and the Sitemap.ascx.cs

Code: Select all

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CommerceBuilder.Common;
using CommerceBuilder.Utility;
using CommerceBuilder.Products;
using CommerceBuilder.Catalog;

public partial class ConLib_SiteMap : System.Web.UI.UserControl
{
    static String myCategoryLinks = "";
    static int recursiveCount = 0;
    protected void Page_Init(object sender, EventArgs e)
    {

    }

    protected void Page_Load(object sender, EventArgs e)
    {
        recursiveCount = 0;
        myCategoryLinks = "";
        CategoryLinks.Text = "<table width='100%' cellpadding=5><tr><td style='vertical-align:top'>";
        RecursiveLoadParents(0, "&nbsp;",20);
        CategoryLinks.Text += myCategoryLinks + "</td></tr></table>";
    }

    protected static void RecursiveLoadParents(int CatId, string delimeter, int fontsize)
    {
        fontsize = fontsize - 2;
        if (CatId > 0)
            delimeter = "&nbsp;&nbsp;&nbsp;&nbsp;" + delimeter;
        CategoryCollection cc = CategoryDataSource.LoadForParent(CatId, true);
        foreach (Category c in cc)
        {
            recursiveCount = recursiveCount + fontsize;
            if (recursiveCount >= 1500)
            {
                myCategoryLinks += "</td><td style='vertical-align:top'>";
                recursiveCount = 0;
            }
            myCategoryLinks += delimeter + "<span style='font-size:" + fontsize + "px'><a href='" + c.NavigateUrl.Substring(2) + "'>" + c.Name + "</a></span><br>";
            RecursiveLoadParents(c.CategoryId, delimeter, fontsize);
        }
    }
}
The "recursiveCount >=1500" is what determines the height of the stacks. You can play around with that number.
This will only build a sitemap of links for the category pages. If you need to add static pages, etc, you'll have to do that part manually.

Hope this helps.

Scott

Re: Site Map Page for Users on Storefront

Posted: Wed Sep 17, 2008 3:37 pm
by ajasko
Thanks for this! Sorry for my lack of competency, but how would I post this on a page in the storefront? (say on sitemap.aspx for example).

Re: Site Map Page for Users on Storefront

Posted: Wed Sep 17, 2008 6:36 pm
by Tomgard
Just finished my MANUAL creation of a site map and you post this! :)

I'd rather use this - thank you for posting. I was told that a good SEO practice is to keep the links on a page to under 100. I am WELL over that number with my site map. Do you think it is possible to add pager controls to such a page?

Re: Site Map Page for Users on Storefront

Posted: Thu Sep 18, 2008 7:25 am
by heinscott
Thanks for this! Sorry for my lack of competency, but how would I post this on a page in the storefront? (say on sitemap.aspx for example).
Make your file (probably the best way would be to copy Webpage.aspx), and rename it to SiteMap.aspx (don't accidently overwrite the sitemap.aspx in the root directory!). Next, when you navigate to that page (when logged in), edit the page, and go to the content section. Hit the edit button, then choose "Manage Scriptlets". On the right side of the screen, choose "Content" from the dropdown, then type a name (Probably SiteMap). Click Add. Then only part that is necessary to edit in this next screen is the content section. Add the line

Code: Select all

[[Conlib:Custom/Sitemap]]


The other two files I send, just make sure you put them in the Conlib/Custom directory.

That should do it for you.

As for paging controls...

You could definitely do that, although, my code is not setup that way. Probably if you, instead of adding links to the asp:Literal, were to add the data to some type of object, you could then populate a grid with the information, and use paging controls that way. I didn't want to go to all that hassle... :)

Hope this helps.

Scott

Re: Site Map Page for Users on Storefront

Posted: Thu Sep 18, 2008 7:22 pm
by ajasko
It works!

Re: Site Map Page for Users on Storefront

Posted: Thu Sep 18, 2008 8:08 pm
by combra
I got part of this to work, as it shows the main categories, but none of the child categories (basically the products). What could I have done wrong?

Re: Site Map Page for Users on Storefront

Posted: Thu Sep 18, 2008 8:19 pm
by Tomgard
I dont think it is supposed to show the products. Only Category/Sub/Sub

Re: Site Map Page for Users on Storefront

Posted: Thu Sep 18, 2008 10:43 pm
by mazhar
If you want to show products as well then you must load the catalog nodes. For example in this case the RecursiveLoadParents method should be something like below

Code: Select all

protected static void RecursiveLoadParents(int CatId, string delimeter, int fontsize)
    {
        fontsize = fontsize - 2;
        if (CatId > 0)
            delimeter = "&nbsp;&nbsp;&nbsp;&nbsp;" + delimeter;
        CatalogNodeCollection cc = CatalogNodeDataSource.LoadForCategory(CatId, true);
        foreach (CatalogNode c in cc)
        {
            recursiveCount = recursiveCount + fontsize;
            if (recursiveCount >= 1500)
            {
                myCategoryLinks += "</td><td style='vertical-align:top'>";
                recursiveCount = 0;
            }
            myCategoryLinks += delimeter + "<span style='font-size:" + fontsize + "px'><a href='" + c.NavigateUrl.Substring(2) + "'>" + c.Name + "</a></span><br>";
            RecursiveLoadParents(c.CatalogNodeId, delimeter, fontsize);
        }
    }

Re: Site Map Page for Users on Storefront

Posted: Mon Nov 10, 2008 2:46 pm
by Tomgard
What if I wanted to show JUST top level categories in my site map? This code exposes 1200+ links in my site map and my SEO does not like that!

Re: Site Map Page for Users on Storefront

Posted: Tue Nov 11, 2008 7:14 am
by mazhar
You can try by putting some level support. For example change the function

Code: Select all

RecursiveLoadParents(int CatId, string delimeter, int fontsize)
to

Code: Select all

protected static void RecursiveLoadParents(int CatId, string delimeter, int fontsize,int level)
    {

        if (level <= 0)
            return;
        level--;
        fontsize = fontsize - 2;
        if (CatId > 0)
            delimeter = "&nbsp;&nbsp;&nbsp;&nbsp;" + delimeter;
        CategoryCollection cc = CategoryDataSource.LoadForParent(CatId, true);
        foreach (Category c in cc)
        {
            recursiveCount = recursiveCount + fontsize;
            if (recursiveCount >= 1500)
            {
                myCategoryLinks += "</td><td style='vertical-align:top'>";
                recursiveCount = 0;
            }
            myCategoryLinks += delimeter + "<span style='font-size:" + fontsize + "px'><a href='" + c.NavigateUrl.Substring(2) + "'>" + c.Name + "</a></span><br>";
            RecursiveLoadParents(c.CategoryId, delimeter, fontsize,level);
        }
    }
and update the following statement in Page_Load

Code: Select all

RecursiveLoadParents(0, "&nbsp;", 20);
to

Code: Select all

RecursiveLoadParents(0, "&nbsp;", 20,5);
Where the last five the depth level

Re: Site Map Page for Users on Storefront

Posted: Tue Nov 11, 2008 8:11 am
by kastnerd
I would have 2 site maps. One for the users, and one using the official site map format for search engines.

Re: Site Map Page for Users on Storefront

Posted: Tue Nov 11, 2008 9:33 am
by jmestep
You can generate a sitemap.xml for search engines under the Website-XML Sitemap button in the admin.

Re: Site Map Page for Users on Storefront

Posted: Tue Nov 11, 2008 10:24 am
by mazhar

Re: Site Map Page for Users on Storefront

Posted: Wed Nov 12, 2008 3:33 pm
by Tomgard
I was not able to use the code provided by Mazhar to create a site map for just top level categories. I tried several different changes to make it work. Beyond my capabilities at this point.

Re: Site Map Page for Users on Storefront

Posted: Thu Nov 13, 2008 3:59 am
by mazhar
I was not able to use the code provided by Mazhar to create a site map for just top level categories. I tried several different changes to make it work. Beyond my capabilities at this point.
Here is the site map control i modified for levels support.