Menu breadcrumb

Topics: ASP.NET 2.0, Business Logic Layer, Controls, Themes
Jul 1, 2015 at 1:55 PM
Hello,
Since this is a very important element for the search engines and to have a good positioning. Someone has managed to implement a menu bredacrump post in their blog?

Let me know
Fabry
Feb 8 at 1:09 PM
Someone has a solution?
Feb 8 at 3:18 PM
I concur with fabry19dice--a menu breadcrumb solves several different use-cases--such as, SEO, user navigation (particularly large blogs), etc.
Feb 8 at 7:43 PM
I'm using a breadcrumb, it works on posts, BE pages and custom pages and incorporates Rich Snippets microdata where hierarchy is represented by positional numbering.

Currently this exists in site master code behind and hooks into some custom utility routines, however, the following extract although not useable outwith may be useful for picking out the logic.
    private void AddBreadcrumb()
    {
        var crumb = new HtmlGenericControl("p");     
        crumb.Attributes.Add("id", "crumb");
        crumb.InnerHtml = GetBreadcrumb();
        
        cphCrumb.Controls.Add(crumb);
    }

    private string GetBreadcrumb()
    {
        const string crumbLink = "<span itemprop='itemListElement' itemscope itemtype=\"http://schema.org/ListItem\" >" +
        "<a class='trailLink' href=\"{0}\" itemprop='item'><span itemprop='name'>{1}</span></a><meta itemprop='position' content=\"{2}\" />" +
            "</span>";
        const string crumbSeparator = "<span class='crumbSeparator'> / </span>";               
        
        string crumb = string.Empty;
        int pos = 2;

        bool useAllPostsLink = inPosts && currentPageType != cPageType.AllPosts;

        string allPostsLink = useAllPostsLink ?
            string.Format(
                crumbLink,
                Utils.RelativeWebRoot + "?page=1",
                allPostsLabel,
                pos++
            ) + crumbSeparator : string.Empty;

        string crumbLead = string.Format(
            crumbLink,
            Utils.RelativeWebRoot,
            Resources.labels.home,
            1
        ) + crumbSeparator + allPostsLink;

        if (inPosts)
        {           
            if (currentPageType == cPageType.Cat)
            {
                if (Request.QueryString["id"] != null)
                {
                    Category cat = Category.GetCategory(new Guid(Request.QueryString["id"]));
                    if (cat != null)
                    {
                        Stack<Category> cats = new Stack<Category>();                       
                        var parent = cat.Parent;

                        while (parent != null)
                        {
                            Category parentCategory = Category.GetCategory(parent.Value);
                            cats.Push(parentCategory);                            
                            parent = parentCategory.Parent;                            
                        }
                        
                        while (cats.Count > 0)
                        {
                            Category c = cats.Pop();
                            crumb = crumb + string.Format(crumbLink, c.RelativeLink, c.Title, pos) + crumbSeparator;
                            pos++;
                        }
                                                
                    }
                }                
            }
            else if (currentPageType == cPageType.Post)
            {
                if (Request.QueryString["id"] != null)
                {
                    Post p = Post.GetPost(new Guid(Request.QueryString["id"]));
                    if (p != null)
                    {                        
                        if (p.Categories.Count > 0)
                        {
                            Category firstCat = p.Categories[0];                         
                            Stack<Category> cats = new Stack<Category>();
                            cats.Push(firstCat);
                            var parent = firstCat.Parent;

                            while (parent != null)
                            {
                                Category parentCategory = Category.GetCategory(parent.Value);
                                cats.Push(parentCategory);
                                parent = parentCategory.Parent;                                
                            }

                            while (cats.Count > 0)
                            {
                                Category c = cats.Pop();
                                crumb = crumb + string.Format(crumbLink, c.RelativeLink, c.Title, pos) + crumbSeparator;
                                pos++;
                            }
                        }
                        else
                        {
                            crumb = string.Format(
                                crumbLink,
                                Utils.RelativeWebRoot + "default.aspx?cat=/category/" + Resources.labels.uncategorized,
                                Resources.labels.uncategorized,
                                pos
                            ) + crumbSeparator;
                        }
                    }
                }
            }

        }                     
        
        if (currentPageType == cPageType.Page)
        {
            string pageId = Request.QueryString["id"];
            if (!String.IsNullOrEmpty(pageId))
            {
                //Try and get a BE page.
                BlogEngine.Core.Page p = BlogEngine.Core.Page.GetPage(new Guid(pageId));
                if (p != null && p.Parent != Guid.Empty)
                {
                    Stack<BlogEngine.Core.Page> pages = new Stack<BlogEngine.Core.Page>();

                    while (p.Parent != Guid.Empty)
                    {
                        p = BlogEngine.Core.Page.GetPage(p.Parent);
                        if (p != null)
                        {
                            pages.Push(p);                            
                        }
                    }

                    while (pages.Count > 0)
                    {
                        p = pages.Pop();
                        crumb = crumb + string.Format(crumbLink, p.RelativeLink, p.Title, pos) + crumbSeparator;                        
                        pos++;
                    }
                }                
            }
        }        

        return crumbLead + crumb;
    }
Feb 10 at 10:02 PM
Hi fabry19dice,
I implemented Menu Breadcrumb feature for all pages and all post in certain category called "community",
see my blog Bidwin.org Help Community:
http://community.bidwin.org/post/About-Community
http://community.bidwin.org/page/How-It-Works

the code in page.aspx:
<ul class="breadcrumb">
    <li>
        <a href="<%=Utils.AbsoluteWebRoot %>"><%=Resources.labels.home %></a>
        <span class="divider"></span>
    </li>
    <%= PagePath  %>
    <li>
        <span class="divider"></span>
    </li>
</ul>  
the code in page.aspx.cs:
public string PagePath
{
    get
    {
        string pagePath = "";
        if (this.Page.HasParentPage)
        {
            BlogEngine.Core.Page parentPage = BlogEngine.Core.Page.GetPage(this.Page.Parent);
            pagePath = "<li><a href='" + parentPage.RelativeLink + "'>" + parentPage.Title + "</a><span class='divider'></span></li>";
            if (parentPage.HasParentPage)
            {
                BlogEngine.Core.Page parentParentPage = BlogEngine.Core.Page.GetPage(parentPage.Parent);
                pagePath = "<li><a href='" + parentParentPage.RelativeLink + "'>" + parentParentPage.Title + "</a><span class='divider'></span></li>" + pagePath;
            }
        }
        return pagePath;
    }
}
Feb 10 at 11:00 PM
Thanks for the very useful tips

I will try..

Fabry
Feb 10 at 11:07 PM
Andy apply your code is not so easy!! It would be helpful for everyone to have files easily implement in your site BE.

Robinliug, code is valid also for post.aspx and post.aspx.cs?????
Feb 10 at 11:49 PM
Possibly looks more complicated than it actually is because it includes structured data formatting for rich Snippets and tailored to suit my theme.
When you take that away, all you are doing is checking if you are viewing posts by category or single post, if viewing by single post then get the first post category and use it to cycle up through any parent categories, if viewing by category just use that to reach root. For the purpose of coding, you know when you are viewing by category or post by examining the URL, likewise for pages. I did have this as a separate control that you could drop into the theme, but decided it was easier to just make it part of the theme. I do agree, a ready made breadcrumb would be a nice option to have.
Feb 11 at 8:43 AM
Yes Breadcrumb extension would be useful for each site, Google speaks about importance Breadcrumb here

Google breadcrumbs
Feb 11 at 7:08 PM
fabry19dice wrote:
Andy apply your code is not so easy!! It would be helpful for everyone to have files easily implement in your site BE.

Robinliug, code is valid also for post.aspx and post.aspx.cs?????
Hi fabry19dice, For Post, you need separate code. I have implemented breadcrumb feature for my blog Bidwin.org Help Community, you can take a look here:
http://community.bidwin.org/
Since my blog has been customized by me, you can not directly use my code for post.
Feb 12 at 1:40 PM
Ok if someone can help me to create Breadcrumb for my site, I can pay for this..
Contact me at fabry19dice (at) hotmail . com
Bye
Fabry