List only child pages with a specific label

Michael Danielsson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2013

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

4 answers

1 accepted

1 vote
Answer accepted
Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2013

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")

<strong>Search for "$labelToMatch" Label</strong><br/>

#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)
         <br/>$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    

<br/><br/><strong>$counter pages checked.</strong>

Michael Danielsson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 24, 2013

How do I get this macro to start with the current page and just check its children?

1 vote
Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2013

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

Michael Danielsson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2013

Hi,

I want to do it without any java coding.

Is that possible?

Regards,

Michael Danielsson

Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2013

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.

0 votes
andrew_spencer December 19, 2019

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.

0 votes
Kay Brown
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2013

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events