This post covers the high points of associating and displaying a tagged collection of photos with an individual blog post in Community Server.
Let's say I'm doing a series of Vermont State Of Mind Goodness, using my recent Hike to Camel's Hump Summit post as an example. For each post in the series I want to display four images from a specific photo gallery tag with a link to all photos associated with that post. In this example I want to display photos tagged with "Camel's Hump."
The issues to address would be associating the blog post with the photo gallery tag and displaying those tagged photos in the GalleryPostList control. If you're thinking, hey, just create a tag that matches the blog post title and pass that as a QueryOverride Tags property to GalleryPostList, that's not a good plan. It's too prone to human entry error, long tags like "Hike to Camel's Hump Summit" corrupt the taxonomic nature of tags, and Tags="<%= someTagVar %>" cannot be passed in QueryOverride properties, as only literal and bound values can be used.
We're going to use a WeblogPost PhotoCategoryID ExtendedAttribute to specify the tag categoryID (in cs_post_categories) which we're going to use when generating the GalleryPostList.
Not a whole lot that's interesting here, but it gets us started. Now we can tailor our custom GalleryPostList control to display photos with that categoryID, oh yes, and at the custom size we want to display those photos. We'll use custom GalleryPostList and GalleryPostImage controls on the web page, with an interesting observation that, with the exception of PageSize, we're not passing any QueryOverrides to get the job done.
<DBVTControl:SidebarGalleryPostList runat="server">
<QueryOverrides PageSize="4" runat="Server" />
<HeaderTemplate>
...
<ItemTemplate>
<CSGallery:GalleryPostData LinkTo="ViewPicture" runat="server">
<ContentTemplate>
<DBVTControl:GalleryPostImage ImageType="Micro" runat="server"/>
</ContentTemplate>
</CSGallery:GalleryPostData>
</ItemTemplate>
...
</DBVTControl:SidebarGalleryPostList>
We need to specify a CategoryID in the GalleryPostQuery, so even though the GalleryPostList is using the context of a Photo Gallery (the lights are on but nobody's home), we can use the WeblogControlUtility to retrieve the current weblogpost, and thus the post's "PhotoCategoryID" extended attribute integer.
I think we've seen the DBVTConfiguration in play in previous posts. The custom CSConfiguration service is a staple in the DBVT Community Server Customization arsenal. Here it's serving up a site default PhotoCategoryID for those posts that do not have a set photo categoryID. The idea is to display photos on all Vermont State of Mind Goodness posts, whether a photo categoryID is specified or not.
DBVT\Controls\GalleryPost\SidebarGalleryPostList.cs
WeblogPost post = (WeblogPost) WeblogControlUtility.Instance().GetCurrentPost(this);
int postPhotoCategoryID = Globals.SafeInt(post.GetExtendedAttribute("PhotoCategoryID"),
DBVTConfiguration.GetConfig().DefaultPhotoCategoryID);
query.CategoryID = postPhotoCategoryID;
The GalleryPostImage sets our custom image size, with Micro stepping up as the new Sidebar image size. I didn't want to create a new GalleryImageType enumerator. The DBVTConfiguration is handy here because we can change the dimensions of the images on-the-fly by changing the image height and width settings in the site DBVT.Config file.
DBVT\Controls\GalleryPost\GalleryPostImage.cs
switch (ImageType)
{
case GalleryImageType.Micro:
// DBVT Modified - Micro is the new Sidebar - ha-ha
DBVTConfiguration dbvtConfig = DBVTConfiguration.GetConfig();
settings = new GalleryImageSettings(dbvtConfig.SidebarImageWidth,
dbvtConfig.SidebarImageHeight, Quality, true);
settings.GalleryImageType = GalleryImageType.Other;
image.ImageUrl = ImageHandling.GetPictureUrl(post, settings);
image.Height = dbvtConfig.SidebarImageHeight;
image.Width = dbvtConfig.SidebarImageWidth;
break;
Oh, I guess you want to see photos now! Geez.