Visible pages in the root - Odd behaviour

I have an about page in my root in the panel. I don’t like the visible feature but I have no better option this time so I tried it.

The about page was the only visible page. It was not easy to figure out how to get just that visible page.

Returns 0

Wrong for me.

<?php echo page()->children()->visible()->count(); ?>

Returns 0

Wrong for me.

<?php echo pages()->visible()->count(); ?>

Return 1

Correct for me.

<?php echo site()->index()->visible()->count(); ?>

Why does not the first two work? I’m on the site root/home on front end, not in a page.

1 Like

That’s easy to explain:

page() fetches the homepage. So unless you don’t have any subpages in your home folder, it’s correct that you get 0 here.

pages() does not exist.

the correct way would be either

if you are in a template or snippet


if you are in a plugin


sorry, I’m wrong about pages()

I added that as a helper to build collections of pages. I admit that this is not clear on first sight. I might need to change that or document it better.


Thanks! That explains it.

I would prefer to have both…




…in the docs. Then we can easily find the version we need, both for the template / snippet and for the plugin.

For me, I was testing the Patterns plugin and needed the functions for the config file. Generating a topmenu.