This project is read-only.

Find the category/s of current post.

Topics: ASP.NET 2.0, Themes
Nov 9, 2010 at 10:08 AM

I am trying to create recent posts in  particular Category based on current viewed post .

Is it possible ?

Also i am want to limit the posts by category limit to 10.

The prob is that i am unable to find how to get the category of the currently served Post.

Plz help.

Thanks in advance..

Nov 9, 2010 at 5:41 PM

Each Post has a "Categories" property.  It's a list of Categories (0 or more).  Here's some code from PostViewBase in BE (as an example) that iterates thru all the categories for a particular post.

protected virtual string CategoryLinks(string separator)
	var keywords = new string[this.Post.Categories.Count];
	const string Link = "<a href=\"{0}\">{1}</a>";
	for (var i = 0; i < this.Post.Categories.Count; i++)
		var c = Category.GetCategory(this.Post.Categories[i].Id);
		if (c != null)
			keywords[i] = string.Format(CultureInfo.InvariantCulture, Link, c.RelativeLink, c.Title);

	return string.Join(separator, keywords);