views:

85

answers:

1

I'm using blogengine.net. I would like to show a default image in the H1 if a particular post is in a particular category. For instance if a post is in the Podcasts category I'd like to display one image and if a post is in the Blog category I'd like to display another.

I have the CSS figured all, all I want to do is change the class, ie: <h1 class="CHANGE"></h1> based on the category, but in order to do so I need to know whether a post is in a category or not.

I started building an extension for the POST_SERVING event, but there is no Post.IsInCategory method. Barring creating my own method in the Source, can someone suggest a better way?

A: 

If your extension is wired to the Post_Serving event, then the first argument that gets passed to your EventHandler (sender) is a Post object. If you cast it as Post, then you can access the Categories property of the current post.

  private static void Post_Serving(object sender, ServingEventArgs e)
  {
      Post thePost = sender as Post;
      foreach (Category cat in thePost.Categories)
      {
          // do something
      }
  }
Rafe