Breadcrumbs for Blog and categories

Topics: ASP.NET 2.0, Controls
Sep 3, 2012 at 10:23 AM

This is code to have category wise breadcrumbs and post for blogengin,currently there is page level breadcrumbs are available.So I coded it for my self.

You can copy paste this code in breadcrumbs.cs file in breadcrumb extension.

 

 string formatplain = "<span>{1}</span>";
        Guid objid = new Guid();
        Guid catid = new Guid();
        if (!String.IsNullOrEmpty(Request.QueryString["id"]))
        {
            objid = new Guid(Request.QueryString["id"]);
        }
        if (!String.IsNullOrEmpty(Request.QueryString["catid"]))
        {
            catid = new Guid(Request.QueryString["catid"]);
        }
        string objName="";
        string objUrl="";

        if (Category.GetCategory(catid) != null)
        { 
            if (Post.GetPost(objid) != null)
            {
                Post post = Post.GetPost(objid);
                objName = post.Title;
                links.Add(string.Format(formatplain, objUrl, objName));
                //List<Category> cats = post.Categories;
            }
               Guid parentid = new Guid();
               parentid = catid;
                if (Category.GetCategory(parentid).Parent != null)
                {
                    while (Category.GetCategory(parentid).Parent != null)
                    {    
                        links.Add(string.Format(format, Category.GetCategory(parentid).AbsoluteLink.AbsolutePath, Category.GetCategory(parentid).Title));
                       parentid = Category.GetCategory(parentid).Parent.Value;
                    }
                }
                else
                {
                    objName = Category.GetCategory(catid).Title;
                    objUrl = Category.GetCategory(catid).AbsoluteLink.AbsolutePath;
                    links.Add(string.Format(format, objUrl, objName));
                }
        }
        else
        {
            if (Category.GetCategory(objid) != null)
            {
                Guid parentid = new Guid();
                parentid = objid;
                if (Category.GetCategory(parentid).Parent != null)
                {
                    while (Category.GetCategory(parentid).Parent != null)
                    {
                        links.Add(string.Format(format, Category.GetCategory(parentid).AbsoluteLink.AbsolutePath, Category.GetCategory(parentid).Title));
                        parentid = Category.GetCategory(parentid).Parent.Value;
                    }
                }
                else
                {
                    objName = Category.GetCategory(objid).Title;
                    objUrl = Category.GetCategory(objid).AbsoluteLink.AbsolutePath;
                    links.Add(string.Format(format, objUrl, objName));
                }
            }
        }

 

also you need to pass as custom titles in postlist page to have category id on breadcrumb.cs

in postlist.cs in for loop of "post".\

 Literal lnkforTitle = (Literal)postView.FindControl("ltrlinkTitle");
                string url = this.Request.RawUrl.ToUpperInvariant();
                if (postView.ShowExcerpt == true)
                {
                    if (url.Contains("?TAG=/"))
                    {
                        lnkforTitle.Text = "<a href='" + post.RelativeLink + "' class='taggedlink'>" + post.Title + "</a>";
                    }
                    else if (url.Contains("/CATEGORY/"))
                    {
                        lnkforTitle.Text = "<a href='" + post.RelativeLink + "?catid=" + CatID + "' class='taggedlink'>" + post.Title + "</a>";
                    }
                }
                else
                {

                    lnkforTitle.Text = post.Title;
                }

Nov 21, 2014 at 8:53 AM
Hi

Very Interesting, but it's possible to have the code of breadcrumbs.cs ? in BE extensions is not more available!

someone who has it and uses it for your site, can be put here?

Thank you very much

Fabry