How to add "Postdate" widget to the blog demo

This is a tiny extension of the well known "blog demo". The purpose of this portlet is to display the posted date in the title line at the head of the post as following picture shows.

Posted Image

  • Copy and paste this php script as blog/protected/components/PostDate.php.



class PostDate extends Portlet {

  public $cssClass='postdate';

  public $ct;


  protected function renderContent()


    echo "<center><font size=\"3\">\n";

    print $this->ct;

    echo "</font></center>\n";



  • Add following css at the end of blog/css/main.css or some other appropliate place.





      margin: 0;

      padding: 3px;




  • Modify the source code of the blog demo(blog/protected/views/post/_post.php) as follows.


<div class="title">

-  <?php echo CHtml::link(CHtml::encode($post->title),array('post/show','id'=>$post->id)); ?>

+     <table><tr><td>

+       <?php $this->widget('PostDate', array('ct'=>date('F<\b\r>j', $post->createTime))); ?>

+     </td>

+     <td> <?php echo CHtml::link(CHtml::encode($post->title),array('post/show','id'=>$post->id)); ?></td>

+     </tr></table>


Have fun ;)

[Updated: Feb 22, 2009]

Collection of the enhancements:…gdemo-enhanced/