When I looked around at blog templates on different sites, I’m running across more and more templates that expect each post to have an image or two with it in the display template. I think it looks great, but I also think I would post even less if I had to have images in the certain sizes for each and ever post I wanted to make.
In thinking about it however, I decided it would work out pretty well for me if I picked out an image for each category and let my theme put the correct image into the template as needed. In my theme, I have only 2 image sizes and there are different enough that I decided to make images for both sizes, but if they were more similar, you might be able to get away with a single image and resizing it on the fly.
Since these images are part of how the post is displayed, the work for this is part of the PostView.ascx of your theme. I used the code behind file for this as well and added the following into my custom PostView class.
1: protected string CategoryImage;
2: protected string FeaturedImage;
3: protected void Page_Load(object sender, EventArgs e)
5:string imageRoot = Utils.AbsoluteWebRoot.ToString() +
8:if (Post.Categories.Count > 0)
9: catImageName = Post.Categories.Title.Replace(".", "");
11: catImageName = "NoCategory";
13: CategoryImage = imageRoot + catImageName + ".jpg";
14: FeaturedImage = imageRoot + catImageName + "Featured.jpg";
Now I had a CategoryImage and FeaturedImage url string that I could use in my PostView.ascx to show the correct image for each post.
1: <img src="<%=CategoryImage %>" alt="<%=Server.HtmlEncode(Post.Title) %>" />
It is a relatively simple trick, but gives you some neat customization on your blog. This concept can be used to do countless customizations to the PostVIew, CommentView and even the Site.Master pages in your theme.