Jump to content

Recommended Posts

Posted

Hi folks,

I am trying to create a counter for items within a section... so say you have a Projects section, on each 'project detail', I'd have a counter and it would say this is page 1/25, for example.

I have the total count, but I'm not sure how to echo out which position/number the current page you are viewing is.

<?php echo $page->eq() ?> / <?php echo $page->parent->children()->count(); ?>

Any thoughts?

Thanks!

Posted

Hi Richard,

Try $page->sort if they are manually sorted. Otherwise you'd need to find the position of the current page inside the $page->parent->children() array.

Posted

Hi Wanze, thanks for your reply. Unfortunately sort doesn't work. Do you know how'd find the position of the current page inside the children() array? Is this in the documentation somewhere?

Posted

You're welcome. I often use the cheatsheet to lookup stuff: http://cheatsheet.processwire.com/

Maybe the following works:

$children = $page->parent->children();
$total = $children->count();
$pagePos = $children->getItemKey($page) + 1; // Assume the keys are zero based
  • Like 4
Posted

That's really great, Wanze. I didn't think about getItemKey so that has helped me loads. Really appreciate the time here.

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...