Finding content

N2's API provides a few options to help finding items stored in the system.

Getting the children of a page 

The most straight-forward would be iterating the page tree using the GetChildren method. An important distinction between the GetChildren() method and the Children collection is that GetChildren filters out items not accessible to the currently logged on user. It's a good idea to use GetChildren unless you really want all items regardless of permissions.

The GetChildren has a few overloads. E.g. you can pass a filter object to the method. The code below will output the titles of pages below the root page of the type NewsPage. If there are unpublished or secured pages these will also be outputted since the AccessFilter wasn't passed.

Traversing child pages recursively 

The code until now didn't consider pages deeper in the page hierarchy. To find pages on deeper level you could create a recursive method. This code will return all news pages below the starting point accessible to the current user. 

Querying for pages

Another option for finding items is the item finder API. The code below will return all news pages (regardless of location or security considerations). 

With the finder it isn't as straight-forward to find items below a certain parent. One option would be using the ParentFilter.

Two approaches at finding items

Traverse the tree and find all news published within the latest month. Sort by published date. 

Same thing but using the finder. 

An example

Lets say we want to display a news bill on the start page. For this we've deviced a detail on the news page: IsNewsBill. We'll use this find the latest news bill to display.

And this is how we find it: