How do I create an extension for BlogEngine.net that addresses whether a post is in a specific category?

I am using blogengine.net. I would like to show a default image in H1 if a specific post is in a specific category. For example, if a post is in the Podcasts category, I would like to display one image, and if the post is in the Blog category, I would like to display another.

I have CSS, all I want to do is change the class i.e. <h1 class="CHANGE"></h1>

based on the category, but for this I need to know if the post is in a category or not.

I started creating an extension for the POST_SERVING event, but there is no Post.IsInCategory method. If disallowing creation of my own method in Source, can anyone suggest a better way?

0


source to share


1 answer


If your extension is connected to the Post_Serving event, then the first argument passed to your EventHandler (sender) is the Post object. If you post it as a post, 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
      }
  }

      

0


source







All Articles