This project is read-only.

Show category name

Dec 15, 2008 at 8:06 PM
Is there a any option for displaying the category name on a page? I am especially looking to show this on pages that just have an individual post.
Dec 15, 2008 at 10:22 PM
Well I came up with a pretty ugly way of doing it, but it does it. Hopefully someone knows of a better way, but here is what I have for now:

In themes > Standard (or whatever theme you are using) > PostView.ascx, add this below <div class="post">

   if (Request.RawUrl.ToLowerInvariant().Contains("/post/"))

This really only works, if like on my blog, there is only one category associated with each post.
Dec 15, 2008 at 10:44 PM
Looks like what you have already works for you.  One built-in piece of data you can use instead of checking to see if the Url contains /post/ is the ServingLocation data.  You could replace the IF statement with:

if (this.Location == BlogEngine.Core.ServingLocation.SinglePost)

The possible locations are in the ServingEventArgs.cs file.  Other locations are None, PostList, SinglePage, Feed, Email and Other.
Dec 15, 2008 at 11:05 PM
Thanks that seems much cleaner than checking the URL so I switched to that.

Do you know if there is any decent way to check to see if you are on the blog's home page ? Right now I have to resort to:

if (Page.Title != "Blog Name | Blog Description")

Not pretty :(
Dec 15, 2008 at 11:37 PM
If you're talking about determining if you're on the homepage from PostView.ascx, then you can use essentially the same code.  Just change SinglePost to PostList.

if (this.Location == BlogEngine.Core.ServingLocation.PostList)
Dec 17, 2008 at 4:50 PM
The problem with using PostList is that it evaluates to true not only on the home page, but also on the category pages and probably any page that is not a single post.