Just as it is possible to match against individual fields it is also possible to match against the hierarchy and relationships that existing within your content tree. So lets say we want to get the latest 5 posts from our blog. We might do something like this:
That is much better. HiFi is doing a recursive query. This would return 5 posts, ordered by newest first from ANY feed with the title matching Blog. In most cases, this would just be one blog, but it would also work if you had two feeds with the title "Blog".
It is possible to combine all of the hierarchy matches if you like. For example, here is a query that shows the latest 5 posts with a parent with the url '/blog', that have comments, that are related to the '/development' category:
Using the child hierarchy match, you can make sure that the results you get back have a certain type of child. Too abstract? A great example is wanting to fetch the newest blog posts that have comments. Here is how you would do this:
As you can imagine, this can make your queries quite powerful. Just like with 'parent' it is possible to make the subquery as complex as you like. Here is an example getting the newest posts that have a comment written by Joel or Josh.
This is probably the most common hierarchy match that will get used in your templates. When you use a parent hierarchy match, you essentially saying "find me items whose parent looks like this". A really common example would be to get the latest three blog posts to show on the homepage. Here is how you might do it:
This will get the newest five posts whose parent is a feed with the url '/blog'. When you are putting a subobject in the parent field, there are no additional rules. You can do any kind of match. A great example of this is grabbing the latest items from EITHER a blog OR a news section. Here is how you would do that:
I am now getting the newest five pages with a parent that has '/blog' or '/news' as the url. Notice that in both my primary query and my subquery I made the types more generic. It is easy to forget to add the correct types to your query, so remember to pay attention to this.
The majority of relationships you will deal with as a developer are parent/children relationships. However, HiFi allows for a third kind of relationship, simply called a relationship, that does not rely on the site's hierarchical structure (a.k.a. the site tree).
Categories and authors are a good example of this. Although they are types on par with page and post, they are not children or parents of the content types they are associated with.
Relationships are directional and they have a name. For example, a post is related to a category and the relationship is named 'category'. Authors are the same:
Notice that each 'related' query requires a 'to' or 'from' parameter. The first query gets posts that are related to a certain category (as indicated by category.id). The second retrives any categories related to a specific post. The final query finds all galleries associated with one author.
Note: With parent/children relationships, you can use an id like so: