Adding Time of Day Verbiage to Your b2evolution Blog

Published by Andrew Hreschak in Web Development, b2evolution 0.9.x, PHP
Published on 08/15/05 @ 09:19:00 am using 271 words, and has 22017 views

By default, in a b2evolution blog, as with pratically every other popular blog platform, when a post is published on the blog it is tagged with a time in hours and minutes which reflect when the blog post was published. Obviously I'm not telling you anything here that you don't already know. However, this default behavior can be altered to display a simple "time of day" verbiage rather than the precise time at which the article was published.

In other words, the code below will replace the "posted at: TIMESTAMP" with a timestamp verbiage in any b2evo skin which displays the post time in the normal fashion. For example, "posted: 9:27am" becomes "posted: early morning".

To implement this PHP code hack on your own b2evolution 0.9.x blog system, place this function in your /conf/_hacks.php file:

< ?php
// inputs must be unix timestamp (seconds)
function time_of_day ( $pdate ) {
global $DB , $tableposts ;
$hour = date ( 'H' , $pdate ) ;
switch ( $hour )
{
case 0 :
case 1 :
case 2 :
$tod = 'the wee hours' ;
break ;
case 3 :
case 4 :
case 5 :
case 6 :
$tod = 'terribly early in the morning' ;
break ;
case 7 :
case 8 :
case 9 :
$tod = 'early morning' ;
break ;
case 10 :
$tod = 'mid-morning' ;
break ;
case 11 :
$tod = 'late morning' ;
break ;
case 12 :
case 13 :
$tod = 'lunch time' ;
break ;
case 14 :
$tod = 'early afternoon' ;
break ;
case 15 :
case 16 :
$tod = 'mid-afternoon' ;
break ;
case 17 :
$tod = 'late afternoon' ;
break ;
case 18 :
case 19 :
$tod = 'early evening' ;
break ;
case 20 :
case 21 :
$tod = 'evening time' ;
break ;
case 22 :
$tod = 'late evening' ;
break ;
case 23 :
$tod = 'late at night' ;
break ;
default :
$tod = '' ;
break ;
}
//return $tod;
echo $tod ;
} ?> 

The particular 'time of day' verbiage can, of course, be altered to suit your particular preferences...

Next, in your skin's _main.php file, replace your post time section with this:

< ?php time_of_day(abs(strtotime($Item->issue_date))); ?>

Contemporaneous Auditory Narcotics:
or, What my speakers are currently pumping...
Hi Fidelity Dub Sessions Chapter 1

No feedback yet