[Résolu] Need help building a view to display page heirachy
This support ticket is created Il y a 6 années. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I have a series of top level pages, with a range of other pages underneath. I'm trying to build a view to display all the pages that are children/grandchildren/greatgrandchildren of each top level page. Think of it as a "table of contents" type thing for each section of the site.
Here's an example of structure (just set up using standard page parent relationships):
Page A
--Page B
----Page C
----Page D
----Page E
--Page F
--Page G
Page H
--Page I
--Page J
Page K
--Page L
--Page M
So on pages A-G for example, I need a series of nested lists to represent that structure. The list would end up being:
Page A
--Page B
----Page C
----Page D
----Page E
--Page F
--Page G
And that exact same list needs to appear on pages A-G to enable navigating to brother/parent/grandparent/child pages.
Hopefully that makes sense- thanks in anticipation of your help!
You will need nested Views for each level of the hierarchy, so if you have root pages, child pages, and grandchild pages, you would need 3 Views, one for each level.
For the first level you would show pages and include a Query Filter for the post parent (the native WordPress concept) where there was no parent, as shown in the screenshot.
The in the Loop Output section include the page title, and a nested View that will display the next level of pages.
In that second View it will display pages and have a Query Filter that this time filters by "Parent is the current post in the loop".
In the Loop Output section you will output the page title (indented) and the next nested View.
This 3rd View will be identical to the second, but you cannot re-use the second because it would create an infinite loop.
If you end up adding additional depth of pages to the hierarchy you would need to add more Views.
One small tweak: that method shows every top level page and it's children. I want to display only one top level page and it's all of its various children/grandchildren- so it's just for that section.
In any View there is a Query Options setting "Don't include current page in query result" which you will need to un-check if you want to include the current page.
If you only want to display one particular top-level page and its descendants, then your first View needs another Query Filter to specify which page to show.
So you will add a post ID filter, as shown in the screenshot.
If you only ever want to show the same top level page you can manually enter the page ID.
If you want to display this in different places with different pages then you should choose to pass the ID as a shortcode attribute.
Then when you insert the first View shortcode where you want it to appear, add an attribute (whose name corresponds to that chosen in the Query Filter) for which page should be the top-level page.
If you want the top level page to be the currently displayed page then you can generate the id for that shortcode attribute using the wpv-post-id shortcode which will be replaced by the id of the current post (or page).
Thanks re: the first part, I can't believe I missed that.
I'm a little confused by the second part though. Here's a link to my site hidden link (it's registered under my work toolset account- just find it easier to communicate through my personal one)
In the screenshot, I want to display only the relevant section. See how the page/menu structure relates to what shows up in the sidebar?
So, for example, on the "Other Procedures" page and any of it's children, I need to display just the part that relates to that section- see second screenshot
Obviously it needs to be dynamic- if i'm on the hidden link page, I want the sidebar to list all the conditions.
So, if you are on the Conditions page you want the sidebar to list Conditions and then the sub-pages of Conditions.
So for your main View, add a Query Filter for post id where the id is provided by a shortcode attribute. By default the attribute will be "ids". See the screenshot.
Actually, because you are explicitly passing the page id the filter to select top-level posts with no parent is redundant and can be deleted.
Then where you insert the View, do it like so, where you pass the id of the current page:
The same sidebar widget is added to all pages, so you are displaying the same initial View on all pages, yes?
Can you just check that the wpv-post-id shortcode is generating the correct id for the ids attribute?
Add the shortcode directly to the widget (before where you insert the View), then visit pages, top-level pages and second-level pages, and verify that the id shown is the id of the page you are currently looking at.
And all is working fine - see the attached screenshots comparing my version with yours. So, my new question: is it possible to achieve the same thing using built-in toolset functionality? Is there a shortcode/method that will achieve what i've achieved through that PHP?