Ektron list based on taxonomy id


/ Published in: C#
Save to your folder(s)

The following code retrieves a list of content based on a taxonomy id. The list is bound to a repeater that display a preview of the content with a quick link to a content page. The content comes in based on the previous taxonomy id but exposes a content list which can be used gather the html property's. Then I use a regex to take our specific nodes for the preview columns in my table.


Copy this code and paste it in your HTML
  1. //Global Variables
  2. public MatchCollection priceMatch;
  3. public MatchCollection bathroomCollection;
  4. public MatchCollection bedroomCollection;
  5. public MatchCollection LandsizeCollection;
  6.  
  7. /* List content based on taxonomy */
  8. TaxonomyItemManager manager = new TaxonomyItemManager();
  9. TaxonomyItemCriteria criteria = new TaxonomyItemCriteria();
  10. criteria.AddFilter(TaxonomyItemProperty.TaxonomyName, CriteriaFilterOperator.EqualTo, community_name);
  11. List<TaxonomyItemData> ccdata = manager.GetList(criteria);
  12.  
  13.  
  14. /* Gather content preview info */
  15. ContentManager cm = new ContentManager();
  16. ContentTaxonomyCriteria criteria1 = new ContentTaxonomyCriteria(ContentProperty.Id, EkEnumeration.OrderByDirection.Ascending);
  17.  
  18. /* Filter content based on taxonomy id based on the previous criteria filter */
  19. criteria1.AddFilter(ccdata[0].TaxonomyId, true);
  20. List<ContentData> contentList1 = cm.GetList(criteria1);
  21.  
  22. /* Parse xml to get price of specific mhc property */
  23. Regex regexPrice = new Regex(@"(?<=\bPropertyTax>\b)[0-9\,]+");
  24. Regex regexBathrooms = new Regex(@"(?<=\bBathrooms>\b)[0-9\,]+");
  25. Regex regexBedrooms = new Regex(@"(?<=\bBedrooms>\b)[0-9\,]+");
  26. Regex regexLandsize = new Regex(@"(?<=\bLandSize>\b)[a-z0-9\,\.\'\ ]+");
  27.  
  28. DataTable dt = new DataTable();
  29. dt.Columns.Add("PropertyName");
  30. dt.Columns.Add("Bed");
  31. dt.Columns.Add("Bath");
  32. dt.Columns.Add("SquareFeet");
  33. dt.Columns.Add("PricePerMonth");
  34. dt.Columns.Add("Link");
  35.  
  36. List<string> prices = new List<string>();
  37. List<string> bathrooms = new List<string>();
  38. List<string> bedrooms = new List<string>();
  39. List<string> sqft = new List<string>();
  40.  
  41.  
  42.  
  43. for (int i = 0; i < contentList1.Count; i++)
  44. {
  45.  
  46. priceMatch = regexPrice.Matches(contentList1[i].Html);
  47. foreach (Match m in priceMatch)
  48. {
  49. prices.Add(m.Value);
  50.  
  51. }
  52.  
  53. bathroomCollection = regexBathrooms.Matches(contentList1[i].Html);
  54. foreach (Match m in bathroomCollection)
  55. {
  56. bathrooms.Add(m.Value);
  57.  
  58. }
  59.  
  60. bedroomCollection = regexBedrooms.Matches(contentList1[i].Html);
  61. foreach (Match m in bedroomCollection)
  62. {
  63. bedrooms.Add(m.Value);
  64.  
  65. }
  66.  
  67. LandsizeCollection = regexLandsize.Matches(contentList1[i].Html);
  68. foreach (Match m in LandsizeCollection)
  69. {
  70. sqft.Add(m.Value);
  71.  
  72. }
  73.  
  74.  
  75. dt.Rows.Add(contentList1[i].Title, bedrooms[i], bathrooms[i], sqft[i], prices[i], contentList1[i].Quicklink);
  76.  
  77.  
  78. }
  79.  
  80.  
  81.  
  82.  
  83. Repeater1.DataSource = dt;
  84. Repeater1.DataBind();

URL: http://i49.tinypic.com/345nacp.jpg

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.