Why is new \Concrete\Core\Page\PageList() not working when logged out?

Hi could someone please shed some light on this for me…

I’m using a PageList to add article numbers to a TopicList Block, however when i’m logged in it works as expected, when i’m logged out the PageList count is -1?

 foreach ($node->getChildNodes() as $topic) {
                    $pl = new \Concrete\Core\Page\PageList();
                    $count = $pl->getTotalResults();
                    if ($count >= 1) {
                    if ($topic instanceof \Concrete\Core\Tree\Node\Type\Category) {
                        ?><li><span></span><span><?php echo $topic->getTreeNodeDisplayName(); ?></span>
                    } else {
                        ?><li><a href="<?php echo $controller->getTopicLink($topic); ?>" <?php
                        if (isset($selectedTopicID) && $selectedTopicID == $topic->getTreeNodeID()) {
                            ?> class="ccm-block-topic-list-topic-selected"<?php
                                 ?>><span><i class="uil uil-tag"></i></span><span><?php echo $topic->getTreeNodeDisplayName(); ?> <span class="badge bg-secondary rounded-pill"><?php echo $count; ?></span></span></a><?php
                    if (count($topic->getChildNodes())) {
                    } ?>

I ran into this also. You can find the answer here:

ultimately the line you’re looking for to get your count is:

$results = count($this->list->getResults());

Edit: Sorry, in your case you need:

$results = count($pl->getResults());
1 Like