Toolset Views allows you to query your WordPress database for post types, users and taxonomies. There are some combinations that allow you to have a View within the loop of another View. This lets you create even more complex displays than you can with a single View.
Let’s take a look at how it works.
If you want to display a taxonomy, or a number of taxonomies, and then display posts within that taxonomy, you can use a Post View inside a Taxonomy View. To explain how this works, it’s best to look at an example, like the WordPress Magazine Site that we created using Views.
The main content area of the Magazine Site looks like this:
To create this layout you would need to create two Views:
- The Taxonomy View that queries the database to display specific taxonomies
- The Post View that displays posts based on the parent taxonomy
This enables you to display dynamic layouts of posts, that are displayed inside a parent View.
Another way to put Views within Views to use is to include a Taxonomy View within a Taxonomy View. This is what we did to create our WordPress Directory Website. Including a Taxonomy View within a Taxonomy View can be a great way to create complex lists that have multiple layers.
The main page on the Directory Website has a “Classifieds Categories” section:
To create this layout you would also need to create two Views:
- The Taxonomy View that queries the database to display parent terms in the taxonomy
- The Taxonomy View that queries the database to display child terms based on the parent
You may need to create a list of users and display a series of posts created by every user, like for example to list the last 5 posts of every administrator.
To create such layout, you need two Views:
- The User View that queries the database to get the users that you want to display.
- The Post Vew that displays posts based on their author.
Then you just need to create the View listing users and add the one you just created as a field to your layout, as explained below.
Pro tip: if you use additional filters in the Posts View, you can achieve quite nice and complex things
Adding a View to a View’s layout is simple, and is done in the same way as you would add a Content Template to a View.
Create your inner child View first, so that you can add it to your parent. Then create the parent View, scroll to the Loop Output section and place your cursor inside the wpv-loop tags. Then click Fields and Views: this will display a pop-up which will show you which Views are available for you to insert.
Simply click on the View’s name and it will be inserted into the loop.