That's untested:
<?php
$c = $modx->newQuery('modResource');
$c->where(array('parent' => $parent));
$c->where(array('published' => '1'));
$c->where(array('deleted' => '0'));
$c->sortby($sortby);
$c->sortdir($sortdir);
$c->select('id');
$i=1;
if ($resources = $modx->getIteration('modResource', $c)) {
foreach ($resources as $resource) {
$modx->setPlaceholder('chapter_' . $resource->get('id'), $i);
$i++;
}
}
the Idea is to have placeholders, which you can use on the rest of your site like this:
or
-
☆ A M B ☆
- 2,475 Posts
Man, I'm gonna reiterate my suggestion to hard-code this. I'm not a Luddite, but if you have trouble with the code, then go for the solution that works. It's such a resource drain to load up some querying/counting plugin to count this stuff that may change at most once a week.
-
☆ A M B ☆
- 326 Posts
Bruno: I'm having a little trouble with that code. The snippet is throwing a 500 error, and I can't figure out what's blowing it up. Maybe a problem with getIteration? I'm on 2.2 RC2, if that matters.
Everett: totally understood. It is a lot of overhead just for a single "window dressing" element on the page. The flipside of that argument, though, is that without it, making a change to an earlier chapter means manually changing it on all of the subsequent chapters. That puts a lof potential maintenance busywork on the client, which is something I try to avoid.
-
☆ A M B ☆
- 318 Posts
Use the idx placeholder from getResources.
For the listing, this should be straightforward. Just sort by publishedon and put a placeholder for idx in your template.
For the individual pages I think you could also do it with getResources. Use the same getResources call as for the listing, using the same parent. But in the template, use the If snippet to check whether the id of the listed resource is the same as the id of the current resource, and if not display nothing. You might have to pass the id of the current resource into getResources as an extra parameter, in which case it should be available in the template as a placeholder.
Maybe later tonight when I have some time I'll play around with it and see if I can put together some working code to post.