Creating php calender for your blog

Creating php calender for your blog
here is a php code for your calender .




function generate_calendar($year, $month, $day_func = NULL, $day_heading_length = 3)
{
$first_of_month = mktime (0,0,0, $month, 1, $year);
static $day_headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
$maxdays = date('t', $first_of_month); #number of days in the month
$date_info = getdate($first_of_month); #get info about the first day of the month
$month = $date_info['mon'];
$year = $date_info['year'];

$calendar = "\n";
$calendar .= "\n";

$calendar .= '';

$weekday = $date_info['wday']; #weekday (zero based) of the first day of the month
$day = 1; #starting day of the month

#take care of the first "empty" days of the month
if($weekday > 0){$calendar .= "";}

include('db.php');
$q = "select date from news";
$buff = mysql_query($q, $linkID);
while ($bline = mysql_fetch_assoc($buff))
{
list($real_date, $junk) = explode(' ', $bline['date']);
$b_days[$real_date]++;
}


#print the days of the month
while ($day <= $maxdays)
{
if($weekday == 7)#start a new week
{
$calendar .= "\n";
$weekday = 0;
}

$linkDate = mktime (0,0,0, $month, $day, $year);
if("$month $day $year"==date('m d Y'))
{
$class='today';
}
else
{

$d = date('m/d/Y', $linkDate);
if($b_days[$d])
{
$class = 'post';
}
else
{
$class = 'empty';
}
}
$link = "dates.php?date=$linkDate";
$calendar .= "\n";

$day++;
$weekday++;
}
if($weekday != 7)
{
$calendar .= '';
}
return $calendar . "\n
$date_info[month], $year
$day
\n";
}
generate_calendar(date('Y'), date('m'), $day_func = NULL, $day_heading_length = 3)
?>

edit

Popular Posts