Monthly Archives widget

And I have added the Monthly Archives widget to the blog demo. The code I have added is very concise since I made use of existing code such as Calendar widget. Followings are all the code that is added.

As usual, you can download it from the google code repositry and can try the demo out. Have fun :)



class MonthlyArchives extends Portlet


  public $title='Monthly Archives';

  public function findAllPostDate()


    $yearmonth = array();

    $posts = Post::model()->findRecentPosts(PHP_INT_MAX);

    foreach ($posts as $post) {

      $ym = date('M, Y', $post->createTime);

      if (!isset($yearmonth[$ym])) {

        $yearmonth[$ym] = 1;

      } else {




    return $yearmonth;


  protected function renderContent()







<?php foreach ($this->findAllPostDate() as $month=>$val): ?>


<?php echo CHtml::link("$month ($val)", CHtml::normalizeUrl(array('post/PostedInMonth',


                                                                  'pnc'=>'c')));  ?>


<?php endforeach; ?>


I've found a bug.

$ym = date('M, Y', $post->createTime);

should be

$ym = date('F Y', $post->createTime);

in order for strtotime() function to work correctly. The SVN has already been fixed.