Strict Standards: Redefining already defined constructor for class Object in /home/dizz/cake_1.2.5/cake/libs/object.php on line 63

Strict Standards: Non-static method Configure::getInstance() should not be called statically in /home/dizz/cake_1.2.5/cake/bootstrap.php on line 47
Croogo Monthly Archives |

Croogo Monthly Archives



Most popular blogging engines usually have some way to categorize articles by month. This short code snippet will allow you to display monthly archives like those blogging engines. I'm assuming that Croogo will eventually add this to the core but for now here is a simple solution.


  • Croogo 1.1
  • MySQL


You must include the two actions into your nodes controller (archives and get_archives) and make sure that you enable them for public access under Users > Permissions in the administration panel. Also included is an element (archives.ctp) that must be placed into your themes element folder. Once you have placed the element into the correct directory go back into your administration panel and then go to Blocks > Blocks and add a new block under the "right" region and then in the elements text input type "archives". This will include the archives.ctp in the right region.


public function get_archives () {
$this->autoRender = false;
$archives = $this->Node->query(
"SELECT MONTH(created) AS month,
YEAR(created) AS year
FROM nodes
WHERE type = 'blog'
AND status = 1
return $archives;

public function archives () {

$this->paginate['Node']['order'] = ' DESC';
$this->paginate['Node']['limit'] = Configure::read('Reading.nodes_per_page');
$this->paginate['Node']['conditions'] = array(
'Node.status' => 1,
'Node.promote' => 1,
'MONTH(Node.created)' => $this->params['month'],
'YEAR(Node.created)' => $this->params['year']
$this->paginate['Node']['contain'] = array(
'Term' => array('Vocabulary')

if (isset($this->params['named']['type'])) {
$type = $this->Node->Term->Vocabulary->Type->findByAlias($this->params['named']['type']);
if (!isset($type['Type']['id'])) {
$this->Session->setFlash(__('Invalid content type.', true));

$this->paginate['Node']['conditions']['Node.type'] = $type['Type']['alias'];
$this->pageTitle = $type['Type']['title'];

$nodes = $this->paginate();

$month = $this->params['month'];
$year = $this->params['year'];

$this->set(compact('month', 'year'));
$this->set('title', get_month($month) . ' ' . $year);

If you have any questions or comments drop me a line below and I will try to get back to you as soon as possible.

Last Updated: December 9th 2009, 6:27am

Download: Croogo Monthly Archives


Chad said on February 4th 2010, 3:19pm
A few things...

get_month function is missing. You can just use something like below to convert month to year:

date('F', mktime(0, 0, 0, $month[1]))

Also, your query in it's current state will group months together - which isn't what we want. For example.. if you have some posts in December 2008, and some posts in December 2009 - it's going to group them together. To get around that, just change the MONTH(created) as month to DATE_FORMAT(created, '%Y/%m') AS month

Then, in your view foreach, you can use explode on the month to get the correct digits:

$month = explode('/', $archive[0]['month']);

That should fix a few of the issues I found so far with this.

Good job!
Chad said on February 4th 2010, 3:20pm
er I meant convert month digit to month text
Manu said on February 19th 2010, 8:41am
Hey Chad, thanks for putting this element together. Its pretty useful and the croogo cms is great. I am wanting to add a counter to the archives so that you can see how many articles are in each month archive. i am familiar with using the counterCache method but the nodes table is set up in a way that seems to make that a bit more tricky. Any ideas?
Add New Comment