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.
- Copy and paste this php script as
blog/protected/components/PostDate.php
.
[php]
<?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.
.postdate
{
-moz-border-radius:7px;
font-size:13pt;
margin: 0;
padding: 3px;
margin-bottom:15px;
background-color:#EEE;
}
- Modify the source code of the blog demo(
blog/protected/views/post/_post.php
) as follows.
[php]
<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>&nbsp;<?php echo CHtml::link(CHtml::encode($post->title),array('post/show','id'=>$post->id)); ?></td>
+ </tr></table>
</div>
Have fun
[Updated: Feb 22, 2009]
Collection of the enhancements: