List only child pages with a specific label

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

3 answers

1 accepted

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>

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

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

Hi,

I want to do it without any java coding.

Is that possible?

Regards,

Michael Danielsson

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.

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

1,132 views 22 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you