public static List <AgilityContentItem> GetRelatedPosts(AgilityContentItem post, IAgilityContentRepository <AgilityContentItem> posts, bool randomize, int limit) { List <AgilityContentItem> relatedPosts = null; int maxLimit = 100; switch (post["RelatePostsBy"] as string) { case "BlogTags": relatedPosts = GetPosts(posts, -1, "", "", post["BlogTagsIDs"] as string, "", "", maxLimit, 0); break; case "BlogPosts": string relatedPostsIDs = post["RelatedPostsIDs"] as string; if (!string.IsNullOrEmpty(relatedPostsIDs)) { relatedPosts = GetPosts(posts, -1, relatedPostsIDs, "", "", "", "", maxLimit, 0); } randomize = false; break; default: //BlogCategories relatedPosts = GetPosts(posts, -1, "", post["CategoriesIDs"] as string, "", "", "", maxLimit, 0); break; } //ensure the current post isn't relating to itself relatedPosts.RemoveAll(i => i.ContentID == post.ContentID); if (randomize) { relatedPosts = BlogUtils.PickRandomItems <AgilityContentItem>(relatedPosts, limit).ToList(); } return(relatedPosts); }