[Resolved] loop through categories used by child posts of current parent post
This thread is resolved. Here is a description of the problem and solution.
Problem:
The issue here that the user wanted to display his Parent/Child post in the format
Category one
- article
- article
Category three
- article
- article
- article
Category six
- article
Category ten
- article
- article
- article
- article
I created a custom post type (journal) with a child post type (article)
What I want to do is:
Create a view that lists the name of all category items in use by the articles of the parent post, with the articles that have that category checked listed beneath the category name.
That's not really the same situation here.
Like the example I linked to.
In my case it is about three levels deep:
Parent post
- select child posts from that parent
- select the categories used by those child posts
- display the first category that has at least one linked child post
- display a loop of all the child posts with that category
- display the next category that has at least one linked child post
- display a loop of all the child posts with that category
etc...
Please read my first question to understand the exact situation.
Thanks!
Since its 3 levels deep then you will need to Create 3 views.
The documentation should've provided you with some background information on the filters to use.
So first you will have a Parent view that lists the Journals.
Journals View
- Child View (lists children of journals)
- Categories view that lists Categories of that children.
- Another Child view of Journals with another filter for the Categories View
This is how I imagine the structure would be, In this case we would need a nesting of 4 different views.
Please let me know if this sounds more like what you are trying to achieve.
Thanks,
Shane
Hi Shane,
That is probably a solution.
I am not sure if we need the first Journal view because this is placed on a single journal page:
1. Journal
2. - Child View (lists children of the current parent)
3. - Categories view that lists Categories of that children.
4. - Another Child view of Journals with another filter for the Categories View
Does this look good to you?
I am not sure how but if you know...
In the parent view I loop through all the categories.
So I reach the first category and now instead of printing the category name before I know if there are articles with this category I pass the category name as an argument to the child view!
In this child view after "[wpv-items-found]" right before the loop starts I print the name of the category!
Here we know there are items to be shown so the category is not empty and can be printed.
Below there is the "[wpv-no-items-found]" and there I just deleted the "No items found" message.