How to get the block IDs of blocks contained in a stack

Permalink
I've already got another question... I am trying to get the ID of all blocks contained in a particular stack based on the handle of the stack. Any ideas? I was thinking that I could do this with a SQL query but I am not familiar enough with the database schema to compose one! Thanks for all the help in advance.

View Replies:
jasteele12 replied on at Permalink Reply
jasteele12
Works for me:
$s = Stack::getByName('Stack Name');
  // $c = new Page();
  // $s->display($c);
$blocks = $s->getBlocks(STACKS_AREA_NAME);
foreach($blocks as $block) {
  echo $block->getBlockID(). ': '.
    basename($block->getBlockPath()). '<br/>';
}

John
globalnerds replied on at Permalink Reply
globalnerds
I just added the following to my header.php

<?php
$s = Stack::getByName('Stack Name');
  // $c = new Page();
  // $s->display($c);
$blocks = $s->getBlocks(STACKS_AREA_NAME);
foreach($blocks as $block) {
  echo $block->getBlockID(). ': '.
    basename($block->getBlockPath()). '<br/>';
}
?>


and received the following error message:

Fatal error: Call to a member function getBlocks() on a non-object in <file system>/header.php