Categories description not seen in page source

Topics: ASP.NET 2.0, Controls, Themes
Aug 5, 2009 at 6:53 PM

Hi ppl,

                  I am new to blogengine , and i have  a doubt.

I have added description to each of my catagory , but i find that the description that i have added is not been seen in the page source (browser page source) .

It would be really helpful for me if some one help me with this issue

 

Thank you

 

Niki

Aug 5, 2009 at 11:40 PM
niki4810 wrote: I just found that you could do this by using  base.AddMetaTag("description" ," your categorydescription"); now having said that is there a way to add  only the current category  description , when a category is clicked from the category list

Hi ppl,

                  I am new to blogengine , and i have  a doubt.

I have added description to each of my catagory , but i find that the description that i have added is not been seen in the page source (browser page source) .

It would be really helpful for me if some one help me with this issue

 

Thank you

 

Niki

 

Coordinator
Aug 6, 2009 at 11:42 PM

In the default.aspx.cs file, there's a DisplayCategories() method.  You can add the "description" meta description when the blog is displaying the posts for a particular category (new code in bold).

private void DisplayCategories()
{
    if (!String.IsNullOrEmpty(Request.QueryString["id"]))
    {
        Guid categoryId = new Guid(Request.QueryString["id"]);
        PostList1.Posts = Post.GetPostsByCategory(categoryId).ConvertAll(new Converter<Post, IPublishable>(delegate(Post p) { return p as IPublishable; }));
        Page.Title = Category.GetCategory(categoryId).Title;

        if (!string.IsNullOrEmpty(Category.GetCategory(categoryId).Description))
        {
            metaDescriptionHandled = true;
            base.AddMetaTag("description", Server.HtmlEncode(Category.GetCategory(categoryId).Description));
        }

    }
}

Towards the end of Page_Load(), a "description" meta tag is already being output.  So you will end up outputting 2 "description" meta tags which is probably not a good idea.  To avoid this, you can create a class level variable (metaDescriptionHandled), set it to true in DisplayCategories(), and then only output a "description" meta tag at the end of Page_Load() if metaDescriptionHandled is false.  So metaDescriptionHandled would be declared at the top, like:

public partial class _default : BlogEngine.Core.Web.Controls.BlogBasePage
{
    bool metaDescriptionHandled = false;
..... existing code .....

And then the end of Page_Load will look like:

AddMetaKeywords();
if (!metaDescriptionHandled)
{
    base.AddMetaTag("description", Server.HtmlEncode(BlogSettings.Instance.Description));
}
base.AddMetaTag("author", Server.HtmlEncode(BlogSettings.Instance.AuthorName));

Aug 7, 2009 at 6:48 PM

Hi Ben,

                     Thank you so much for your response. The information you gave is exactly what I was looking for.

-

Niki