0

I'm using Lemoon CMS. I've created a new Content Type, and i've modified it with new fields and all its working fine.

I created a new user control to show some data from my content type which the field ("isFeatured=true")

How I can customize the code to filter the content, and how i can sort the data by custom added field?

 ContentQuery query = new ContentQuery();
    query.ParentID = 70;
    query.MinDepth = 1;
    query.MaxDepth = 1;
    query.LanguageMode = LanguageMode.Fallback;
    query.SearchNonSearchable = null;
    query.ContentTypes.Add(typeof(Mindroute.Lemoon.Generated.ContentType.ServiceItem).FullName);

    query.ContentTypeMode = ContentTypeMode.Inherit;
    //query.OrderBy.Add(new SortItem(ContentColumn.Columns[6], "desc"));
    Response.Write(ContentColumn.Columns[6]);
    query.PageSize = 8;
    Entries = ContentService.Search(query).Cast<Mindroute.Lemoon.Generated.ContentType.ServiceItem>();
Shiva
  • 6,677
  • 4
  • 36
  • 61

1 Answers1

0

First, I think you can simplify your code that gets the ServiceItems. You could simply use ContentService.GetChildren<ServiceItem>(70) instead of setting up a ContentQuery.

To filter and order by a specific property you could then use Linq like this:

var children = ContentService.GetChildren<ServiceItem>(70);
var filtered = children.Where(x => x.IsFeatured == true);
var ordered = filtered.OrderBy(x => x.SomeOtherProperty);

It is also possible to use ContentQuery to find items with custom properties, you would then need to set ContentQuery.PropertyValue = new PersistedValue("IsFeatured", true);

lajjne
  • 699
  • 5
  • 15