Call to a member function getCollectionID() on a non-object

Permalink
Trying to use the getTotalBlocksInArea() function but get an error:
Call to a member function getCollectionID() on a non-object


The code I'm using is this:
<?php
           $top = new Area('Top');
         $blocks = $top->getTotalBlocksInArea();
         $displayTopColumn = $blocks > 0 || $c->isEditMode();
         if ($displayTopColumn) { ?>
            <div style="padding:25px 10px;">
                <div class="col-sm-12"><?php  $top->display(); ?></div>
            </div>
            <?php  } ?>


I have followed the examples but it doesn't work. Its the latest 5.7 version.

If anyone has an idea I'd be very grateful, thanks!


EDIT!

I just found the solution in another post:
https://www.concrete5.org/community/forums/5-7-discussion/themes-obt...

Andrew wrote:
It's basically the same, except you pass the $c current page object to the getTotalBlocksInArea() method and use the Area class instead of GlobalArea;

$a = new Area('Main');
$total = $a->getTotalBlocksInArea($c);