12:00am March 18, 2008
Code Snippet: Blog Archive Element
This code snippet is a simple example of how I build the "Blog Archive " Element. // get list of blog entries
// ------------------------
$archive = $this->Blog->BlogEntry->findAll(
    null,
    array(
        'BlogEntry.id',
        'BlogEntry.created'
    ),
    'BlogEntry.created DESC',
    null,
    null,
    -1
);

// loop through and build a relative list
// --------------------------------------
for($i=0;$i<count($archive);$i++) {
    $key = date('F Y',strtotime($archive[$i]['BlogEntry']['created']));

    $out[$key][] = $archive[$i]['BlogEntry']['id'];
}
Views  336 Comments  0
Filed under: CakePHP
Add Comment
View Chris Thompson's profile on LinkedIn
Loading...