mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Thu Aug 15, 2002 11:31 pm Post subject: Number of Posts in Calendar |
|
|
Here's a good one. This hack gives you a a tooltip when you hover over the days of the month which are links (i.e. have posts) indicating the number of posts on that day.
in b2calendar.php at line 60, the while loop
Code: | while($calendarmonthwithpost == 0) {
$arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) FROM $tableposts WHERE MONTH(post_date) = '$thismonth' AND YEAR(post_date) = '$thisyear' ORDER BY post_date DESC";
$querycount++;
$arc_result=mysql_query($arc_sql) or die($arc_sql."<br />".mysql_error());
if (mysql_num_rows($arc_result) > 0) {
$daysinmonthwithposts = '-';
while($arc_row = mysql_fetch_array($arc_result)) {
$daysinmonthwithposts .= $arc_row["DAYOFMONTH(post_date)"].'-';
}
$calendarmonthwithpost = 1;
} elseif ($calendar != '') {
$daysinmonthwithposts = '';
$calendarmonthwithpost = 1;
} else {
$thismonth = zeroise(intval($thismonth)-1,2);
if ($thismonth == '00') {
$thismonth = '12';
$thisyear = ''.(intval($thisyear)-1);
}
}
}
|
becomes (note I've wrapped the SQL query for legibility):
Code: | while($calendarmonthwithpost == 0) {
$arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date), count(*) as posts"
. " FROM $tableposts"
. " WHERE MONTH(post_date) = '$thismonth' AND YEAR(post_date) = '$thisyear'"
. " GROUP BY DAYOFMONTH(post_date)"
. " ORDER BY post_date DESC";
$querycount++;
$arc_result=mysql_query($arc_sql) or die($arc_sql."<br />".mysql_error());
if (mysql_num_rows($arc_result) > 0) {
$daysinmonthwithposts = '-';
unset($postsondayofmonth);
while($arc_row = mysql_fetch_array($arc_result)) {
$daysinmonthwithposts .= $arc_row["DAYOFMONTH(post_date)"].'-';
$postsondayofmonth[$arc_row["DAYOFMONTH(post_date)"]] = $arc_row["posts"];
}
$calendarmonthwithpost = 1;
} elseif ($calendar != '') {
$daysinmonthwithposts = '';
$calendarmonthwithpost = 1;
} else {
$thismonth = zeroise(intval($thismonth)-1,2);
if ($thismonth == '00') {
$thismonth = '12';
$thisyear = ''.(intval($thisyear)-1);
}
}
}
|
Then round about line 155 (which has now become line 161) the code which prints the links:
Code: |
$calendarblah = '-'.date('j',$i).'-';
$calendarthereisapost = ereg($calendarblah, $daysinmonthwithposts);
$calendartoday = (date('Ymd',$i) == date('Ymd', (time() + ($time_difference * 3600))));
if ($calendarthereisapost) {
echo '<a href="'.$siteurl.'/'.$blogfilename.'?m='.$thisyear.$thismonth.date('d',$i).'" class="b2calendarlinkpost">';
}
|
becomes:
Code: |
$calendarblah = '-'.date('j',$i).'-';
$calendarthereisapost = ereg($calendarblah, $daysinmonthwithposts);
$poststhisday = $postsondayofmonth[date('j',$i)];
$calendartoday = (date('Ymd',$i) == date('Ymd', (time() + ($time_difference * 3600))));
if ($calendarthereisapost) {
echo '<a href="'.$siteurl.'/'.$blogfilename.'?m='.$thisyear.$thismonth.date('d',$i).'" title="'
. $poststhisday .' post' . (($poststhisday > 1) ? 's' : '') .'" class="b2calendarlinkpost">';
}
|
And that's it. The days in the calendar which are links now have a tooltip giving the number of posts on that day.
Mike |
|