How to Display Number of Child Pages

Feb 27, 2016

In this tutorial, we will look at how to display the number of child pages within a menu. This is ideal for projects that have categories, and could be used for blogs, ecommerce categories, directories, or other similar projects.


Check out the directory on It shows the number of listings for each category. We accomplished this simply by creating a custom template for the auto-nav block.

Although this was built with 5.6, this tutorial should also work just fine with 5.7.

STEP 1: Create a Custom Template

First, we need to set up a custom template for the auto-nav block. This will be used to render a list of pages that will show the number of their child pages at the next level down.

Let's assume you're using a theme package to be used with 5.7.x. Go to /concrete/blocks/autonav and copy the view.php file. Here, we'll call our template "num_child_pages".

Then paste the file into /packages/theme_package/blocks/autonav/templates/num_child_pages.

STEP 2: Modify View File

Now, let's modify the view.php file. Look for the following code (approximately line 117):

foreach ($navItems as $ni) {

After it, copy and paste the following:

$numChildren = $ni->cObj->getNumChildren();

This adds support for showing the number of child pages. Basically, it is looking for how many child pages there are beneath the parent.

Now, replace line 120:

echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</a>';

with this:

echo  '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes  .'">' '. $ni->name . ($numChildren > 0  ? ' (' . $numChildren . ')' : '') . '</a>';

This looks to see if the number of child pages is greater than 0, and if so, display the number.

STEP 3: Apply Custom Template

Now, all you have to do is apply the custom template, and you should see something like the example above!

You can apply the same logic to other blocks, such as Page List and Topic List.

Recent Tutorials
How to update Add-Ons if not on the Update Add-Ons Menu item
Jul 4, 2022

How to manually download an add-on and update it when your site's core versions isn't considered compatible with the add-on version.

Generate a report with author information and form summaries in Concrete CMS.
May 9, 2022

In Concrete CMS, you can use a form to initiate contact between logged-in users and then create helpful reports. After form submissions are collected, they can be searched, sorted, and exported as a spreadsheet. This tutorial will detail how to add author information to a report using the advanced search.

How to clone and customize Atomik theme
Feb 14, 2022
By linuxoid.

How to clone and customize Atomik theme

Update jQuery to 3.5 on Concrete CMS version 8.5.x
Dec 1, 2021
By hissy.

If you have to take some time to fix your site to work with version 9 and want to update jQuery immediately, you can override it.

Add-On Developers: Get Your Add-Ons Ready for Concrete CMS 9.0
Aug 6, 2021
By andrew.

Concrete CMS 9.0 is coming! But there are some changes in version 9 that might affected your add-ons and themes. This document aims to answer questions about the most common ways that your add-ons might need to be changed, and common problems you'll run into.

Permissions for editors in a multilingual site
Jun 2, 2021
By myq.

How to set up a multilingual Concrete CMS site for groups of language-specific editors

Was this information useful?
Thank you for your feedback.