Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get all pages and count of each page in confluence?

Siddheshwar mhetre
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.
November 21, 2014

I want to display all pages and counts in confluence page.

Can we create a macro for that?

Also I want to display the maximum count of pages.

All should be display in table format.

7 answers

1 accepted

2 votes
Answer accepted
Cedric_DEVAUX
Contributor
November 21, 2014

Hi you can try this user macro:

## Macro title: Page counter
## Macro has a body: Y or N (N)
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Cedric DEVAUX
## Date created: 21/07/2014
## Macro to count pages in the space.
## @noparams
## Settings
#set($containerManagerClass=$action.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager=$getInstanceMethod.invoke(null,null))
#set($containerContext=$containerManager.containerContext)
## the spaceManager gives you access to the spaces
#set($spaceManager =$containerContext.getComponent('spaceManager'))
<h2>Page counter per spaces</h2>
<table class="confluenceTable">
        <tr>
            <th class="confluenceTh">Space Name</th>
            <th class="confluenceTh">Count</th>
        </tr>
    #foreach($sp in $spaceManager.getAllSpaces())
    #if($sp.isGlobal())
    <tr>
        <td>
            <a href="/display/$sp.getKey()">$sp.getName()</a>
        </td>
        <td>
            $spaceManager.findPageTotal($sp)
        </td>
    </tr>
    
    #end
    #end
</table>
Siddheshwar mhetre
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.
November 21, 2014

Thanks cedric, this macro is helpful. Also I want a list of all of the pages in Confluence and how many times each has been accessed.

Deleted user December 3, 2014

Any chance we can add some code that would allow for a "total" line at the bottom that sums up Space Page Counts?

Davin Studer
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.
December 3, 2014

Confluence does not keep track of how many times each page has been accessed. At least I've never found it and I've looked all over the database for it.

Rao B November 28, 2020

Hello guys,

With the above code I am getting following error 

Error rendering macro 'pagecounter'

Error occurred rendering template content

 

Could you please help some one here.

 

Thanks in advance.

Nic Brough -Adaptavist-
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.
November 28, 2020

Have you translated the missing tags? 

The answer was posted 6 years ago and when it was imported from the previous system, the xml-like tags were escaped to &lt; and &gt; - that needs to be undone.

Rao B November 29, 2020

Hello @Nic Brough -Adaptavist-

Thanks for your reply. could you please look into the below code.

## Macro to count pages in the space.
## @noparams
## Settings
#set($containerManagerClass=$action.class.forName(‘com.atlassian.spring.container.ContainerManager’))
#set($getInstanceMethod=$containerManagerClass.getDeclaredMethod(‘getInstance’,null))
#set($containerManager=$getInstanceMethod.invoke(null,null))
#set($containerContext=$containerManager.containerContext)
## the spaceManager gives you access to the spaces
#set($spaceManager =$containerContext.getComponent(‘spaceManager’))
<h2>List of Spaces</h2>
<table class=”confluenceTable”>
<tr>
<th class=”confluenceTh”>Space Name</th>
<th class=”confluenceTh”>Page Count</th>
<th class=”confluenceTh”>Last Modified</th>
</tr>
#foreach($sp in $spaceManager.getAllSpaces())
#if($sp.isGlobal())
<tr>
<td>
<a href=”/display/$sp.getKey()”>$sp.getName()</a>
</td>
<td>
$spaceManager.findPageTotal($sp)
</td>
<td>
$sp.getLastModificationDate()
<!–$sp.getLastModifierName()–>
</td>
</tr>

#end
#end
</table>

 

following errors I am getting 

Error rendering macro 'pagecounter'

Error occurred rendering template content

Nic Brough -Adaptavist-
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.
November 30, 2020

I can't tell - you'll need to debug it.  Shorten the macro down to one active line and re-add them one at a time.

Probably more importantly - the code you've got is based on 6 year old code, my best guess would be that the new APIs are different and you'll need to look at how to replace them.

Rao B November 30, 2020

Hello @Nic Brough -Adaptavist- ,

 

Thanks, the above code is working after debug, but is listing all users created date and time but not listing last modification date of particular space, pages.

I tired with $action.dateFormatter.formatDateTime($content.getLastModificationDate()), it will display exact modification date and time for current user.

could you please guide here how to list for all users last modification date.

 

Thanks in Advance

1 vote
Bob Swift
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.
November 21, 2014

Site statistics is an old link, but still valid. Various queries of the Confluence database using SQL for Confluence.

Siddheshwar mhetre
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.
November 24, 2014

Thanks Bob :)

0 votes
Nika Khliobas
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 24, 2021

This macro counts pages only in "site spaces" besides there are "personal spaces" "my spaces" "archived spaces"
Is it possible to make the table display the count of pages from all spaces?

 

0 votes
Miles April 25, 2017

Actually, I found a quicker answer that does not require any developpment: simply search for the wildcard on all pages!

.../dosearchsite.action?cql=siteSearch+~+"*"+and+type+%3D+"page"&queryString=*

0 votes
Siddheshwar mhetre
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.
November 21, 2014

Yes Davin, how can I get this..?

0 votes
Davin Studer
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.
November 21, 2014

Are you saying that you want a list of all of the pages in Confluence and how many times each has been accessed?

0 votes
Nic Brough -Adaptavist-
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.
November 21, 2014

"Display all pages" does not make sense.  You want to include the content of every page in one place?  For even a small Confluence, that's not going to work - you'll have thousands of pages and it'll take too long to build and render.

Or do you mean a list of all pages, just their name?  That's still not much use - a tiny new confluence will quickly have hundreds, and a typical one has tens of thousands.

I'm afraid "counts" makes no sense either.  What are you counting?

Maximum count of pages?  Ok, you want to count pages, what is the criteria?  And what do you mean by "maximum" (As there's no specific limit in Confluence, maximum doesn't make any sense)

I think you need to explain your requirement better.  What question are you trying to answer with these numbers and lists?  Forget about tables, pages, counts for now, just tell us what your user (or you) want to know specifically and why?

Siddheshwar mhetre
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.
November 21, 2014

Thanks for replay, I want to display on any confluence page in following table structure manner. Display all pages in one place with their counts. | All Pages | Count | | | | The table should be display the maximum count of page. Maximum count is when the page get loaded.

Nic Brough -Adaptavist-
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.
November 21, 2014

I'm afraid that does not make it any more clear. The closest I can imagine is not even a table, you just want to know how many pages you have. Your "all pages" column has no data because "all pages" is meaningless. Count is fine - it's the number of pages you have in your installation. It's available on the system-information page, so I imagine it would be quite easy to write a macro to extract it and hence say "this confluence has a total of X pages" There's still no "maximum" there, and "maximum count is when the page gets loaded" is still complete nonsense.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events