boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Number of Posts in Calendar

 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
mikelittle



Joined: 11 May 2002
Posts: 376
Location: UK

PostPosted: Thu Aug 15, 2002 11:31 pm    Post subject: Number of Posts in Calendar Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
.Chris



Joined: 30 Apr 2002
Posts: 186
Location: Hawaii

PostPosted: Fri Aug 16, 2002 12:45 am    Post subject: Reply with quote

OHHH I like this one!

Dang you're hot today!
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group