List only child pages with a specific label
Asked by Michael Danielsson:

Hi

I would like to list only child pages with a specific label in my Confluence page.

I can't see that this is possible with children-display.

Does anyone have a solution?

Regards,

Michael Danielsson


Answers:
author: Matthew J. Horn
body: Here's a user macro that does it (I varied from my suggested approach slightly):

```
## Macro title: Label Search## Macro has a body: N## Body processing: n/a## Output: HTML#### Developed by: Matthew J. Horn## Date created: 10/24/2013## Installed by: Matthew J. Horn## @noparams## Define variables:#set ($labelList = [])## #set ($pageMatches = [])#set ($counter = 0)#set ($labelToMatch = "comments")&lt;strong&gt;Search for "$labelToMatch" Label&lt;/strong&gt;&lt;br/&gt;#macro( process $rp )   #set( $pagelist = $rp.getSortedChildren() )  #foreach( $child in $pagelist )   ## child is of type Page      #set( $labelList = $child.getLabels() )          #foreach ($label in $labelList)        #if ($label == $labelToMatch)         &lt;br/&gt;$child.getTitle() has the "$labelToMatch" label on it        #end      #end      #set( $counter = $counter + 1 )                ## make this       #if( $child.hasChildren() )        #process( $child )     #end  #end#end
```

```
## Check to see if the page is the home page of the space.
```

```
## Otherwise, get to the home page.
```

```
#if ($content.isRootLevel() == "false")
```

```
#set($spaceHome = $space.getHomePage())   #process($spaceHome)#else    #process($content)#end    &lt;br/&gt;&lt;br/&gt;&lt;strong&gt;$counter pages checked.&lt;/strong&gt;
```

comments: author: Michael Danielsson
body: How do I get this macro to start with the current page and just check its children?


author: Matthew J. Horn
body: You should be able to do this with a user macro. On the parent page, get a List of child pages with the getDescendants() method. Then iterate over them and for each page call getLabels(). Check for the label you want, and build a list of the pages that match.

You can basically do all this with the Page class:

<https://docs.atlassian.com/atlassian-confluence/latest/com/atlassian/confluence/pages/Page.html>

hth,

matt

comments: author: Michael Danielsson
body: Hi,

I want to do it without any java coding.  

Is that possible?

Regards,

Michael Danielsson


author: Matthew J. Horn
body: Writing user macros is not at all like Java coding. It uses Java syntax, but you don't do any compilation. Confluence takes care of that for you.


author: andrew_spencer
body: The page properties report can do this, but it will report the child pages' properties rather than a standard page listing. However, it does allow you to filter by label, and in "Add filter" you can limit it to direct children or to descendants of the current page.

That may work for some people who stumble across this question.


author: Kay Brown
body: You could use the reporting plugin and do something like this:

{report-table}

{local-reporter:page:children\|source=Page Name}

{content-filter:label=label name}

{local-reporter}

{report-column:title=Column Title}

{report-info:page:title}

{report-column}

{report-table}

Regards,

Kay