Show only those Childpages that have a specific label
Asked by Christian Jurasz-Kischka:

I'm looking for a way to display a list (ul \& li structure in the result) of all childpages of a certain page, which have a certain label.  
Actually a page tree would be enough for me, but even there I would like to filter for certain labels.  
The attempt with the Reporting PlugIn was not very satisfying, because everything was very slow.


Answers:
author: Bill Bailey
body: Wont the [content-by-label-macro](https://confluence.atlassian.com/doc/content-by-label-macro-145566.html) do the job? You can restrict on label and ancestor/parent.

Otherwise you can write a user macro. I built a child page by label macro based on this code:

<https://github.com/unidwell/confluence-include-child-pages-macro>

With the user macro, you have complete control over the formatting.

comments: author: Christian Jurasz-Kischka
body: Hey, Bill,  
thanks for your macro. It works so far. But unfortunately it only shows the first level of my childpages. And it also shows the content of the respective page.  
What I'm looking for is the possibility to get all pages starting from a certain page with a certain label as a structured list. The result would be a HTML structure with many \<ul\> and \<li\> ;-)  
Would this be possible with your macro?


author: Bill Bailey
body: The link I sent you was to a macro I reworked to develop what you describe: an unordered list (but sortable) of child pages that match a label. In looking at the code, it only does the first level. Let me put together an article with what I have done (it is limited to children -- need to think how to extended it to all decedents).

Stay tuned!


author: Christian Jurasz-Kischka
body: Hello,  
that would be great!!! I already had the idea that it would be enough to create a hierarchical PageTree of all subpages and then to include the labels of the subpages as a CSS class. Then it would be possible to hide certain CSS classes, which are the page labels, by CSS.  
But I am curious if you have an idea for your macro for the other layers. Thanks in advance.


author: Bill Bailey
body: I have created an article that should really help you ;-)

[A-Child-Page-by-Label-User-Macro](https://community.atlassian.com/t5/Confluence-articles/A-Child-Page-by-Label-User-Macro/ba-p/1502246)


author: Christian Jurasz-Kischka
body: Hey Bill,

thanks for the link. That's quite a bit. But as you write correctly, you now have to add the subpages of the subpages as a hierarchical tree. And my know-how for programming macros is also rather hobbyistic.

Will you stick to the matter? I have found a solution for all subpages of a certain page. But unfortunately all pages are displayed in one level. I haven't found a hierarchical page-tree user macro anywhere that you could build on.  
But thanks again.


author: Stephen Ellwood
body: Hey Bill,

\[I am also a huge fan of user macros and would like to learn ;o)\]

I followed the link and saw it was tagged for the server version. Is there any reason why your macro would not work in the Cloud version?


author: Tessa Tuteleers
body: Hi [@Christian Jurasz-Kischka](/t5/user/viewprofilepage/user-id/2553655) ,

I'm trying to understand your question.

If you have a list of items, containing parents and children like a pagetree, and filter out only pages with a certain label, how would your tree handle this?

Say your page has a child that does not have the label you are filtering on, but a child of th?t page does have the label, your tree would break, no?

I think that's why the label filtering macro only shows a flat list of pages instead of a tree.   
Please let me know if I understood incorrect and I'll see if we can figure something else out!

Tessa

comments: author: Christian Jurasz-Kischka
body: That is certainly true, that the described situation could be a problem.

But an idea would be, that the system only looks for labels in the subpages, if the mother page has the corresponding label.

Alternatively you could of course say that all pages are shown in the hierarchy if only one subpage has the label.

But for my problem I can make sure that there is always a continuous path for the pages ;-)


author: Christian Jurasz-Kischka
body: Another idea would be to get all subpages of a page as an unnumbered list (ul - li) and to write the labels as a class into the HTML code. Using CSS you would then simply hide one or the other entry based on the label (as a CSS class).  
But: Who can give me a hint on how to implement this as a macro ;-)


Tags: child-page

confluence-server

label

page-tree

server