I'm Keyvan Nayyeri, a 25 years old Ph.D. student at
the Computer Science department of
the University of Texas at San Antonio.
I'm also
a Software Architect and Developer and previously held a B.Sc.
degree in Applied Mathematics.
This is my blog where I publish content about various topics specifically Programming Languages and Compilers, Software
Engineering and Programming.
Tags are a new feature in Community Server 2.1. Generally tags became a frequently used feature in web applications and websites in latest 2-3 years and Community Server team decided to implement them for this great up to date platform.
In previous versions of Community Server, each application type had its own mechanism to categorize its content. Categories for blog posts and subfolders of file gallery folders were two examples of these mechanisms. But in Community Server 2.1 all previous mechanisms are replaced with tags. This replacement wasn't a deep change from base because most old APIs are still valid and no change is made for them. For example, you can use old blog category APIs (I wrote about them here) in order to select, add, remove and edit tags for blog posts.
On the other hand some new APIs have been added to let you add your forum posts under some specific tags and the way that old categories had been used is replaced with a new approach to show tags in tag clouds.
Another important feature is the ability to list all tags per site, per application, per group or per section and new APIs are added to enable these capabilities. For example if you navigate to this page, can see a global tag cloud for all of my tags on my site.
Primary goal of this CS Dev Guide post is to describe new APIs to get tags for a site, a specific application, a group or a section. Mechanisms to add, remove or delete tags for specific applications are different and depend on that application type. Another topic that will be covered is to get a list of posts that match a tag or a list of tags.
CommunityServer.Components.Tag is code representation of a tag. It's very simple and has two properties to specify its name and total count of posts that are tagged under it.
CommunityServer.Components.Tags namespace has a collection of static functions with several overloads which get some parameters and return an ArrayList of Tag objects for a site, an application type, a group or a section. There are some other static methods that remove unused tags.
The purpose of these methods is obvious from their name and their parameters represent where an overload is helpful. Although there are many methods in this namespace but most of them are overloads. Therefore I list all method names and describe their purpose here:
Here there is a general point that should be mentioned: all above methods identify a group by its GroupID and a section by its SectionID. So they get their parameters as integer values for GroupID and SectionID or an array of integers for GroupIDs and SectionIDs.
Now that we discovered these theories, let's take a look at some examples.
In first example, GetPopularPostID() function returns the PostID for most popular post (post with more views in first page of results when page size is 15) in Weblog application that is tagged under .NET, C# or Community Server. In this code GetPostsMatchingTags() static method is used to get an array of tag names, an ApplicationType enumerator and two integer values for page index and page size of results.
int GetPopularPostID()
{
String[] tags = { ".NET", "C#", "Community Server" };
SearchResultSet set = Tags.GetPostsMatchingTags
(ApplicationType.Weblog, tags, 0, 15);
int mostViews = 0;
int postID = 0;
foreach (Post post in set.Posts)
{
if (post.Views > mostViews)
{
mostViews = post.Views;
postID = post.PostID;
}
}
return postID;
}
Second example, GetActiveTagName() function, uses GetTagsByGroup() static method to return a tag name with more posts for current blog group.
String GetActiveTagName()
{
CSContext context = CSContext.Current;
ArrayList tags = Tags.GetTagsByGroup(context.BlogGroupID);
int postCount = 0;
String mostActiveName = String.Empty;
foreach (Tag tag in tags)
{
if (tag.TotalCount > postCount)
{
postCount = tag.TotalCount;
mostActiveName = tag.Name;
}
}
return mostActiveName;
}
Third and last example, RemoveUnusedTagsFromThisSection() method (and a novel after this name!), uses RemoveUnsedTagsFromSection() static method to remove all unused tags for current section.
void RemoveUnusedTagsFromThisSection()
{
CSContext context = CSContext.Current;
Tags.RemoveUnusedTagsFromSection(context.SectionID);
}
Now playing: Ricky Martin - Save The Dance
J-O Eriksson
Nov 27, 2006 12:55 PM
#
Keyvan Nayyeri
Nov 27, 2006 1:02 PM
#
Community Server Daily News
Nov 27, 2006 1:56 PM
#
Daily News List Blog
Nov 27, 2006 2:12 PM
#
Prog
Nov 27, 2006 2:26 PM
#
Community Server Daily News
Dec 01, 2006 1:59 PM
#
Announcements
Dec 01, 2006 2:54 PM
#
Prog
Dec 01, 2006 3:33 PM
#
Prog
Dec 01, 2006 3:33 PM
#
Sam
Dec 01, 2006 7:46 PM
#
Keyvan Nayyeri
Dec 01, 2006 8:56 PM
#
Community Server
Jan 19, 2007 6:20 PM
#
Paul W
Jun 07, 2007 11:11 AM
#
Paul Schofield
Sep 15, 2007 4:18 PM
#
Gerard
Nov 10, 2008 7:04 PM
#
Hi,
Im trying to add a Related Posts section to the /Themes/Blogs/[theme]/post.aspx page. I found it interesting that this is not an option in the default installation.
Looking at the <CSBlog:WeblogPostList> control, how can I set the QueryOverrides.Tags property to dynamically populate from the BlogPage context?
Thanks
Leave a Comment