Make WordPress Core


Ignore:
Timestamp:
11/03/2003 05:22:01 PM (22 years ago)
Author:
saxmatt
Message:

New calendar code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/b2-include/b2template.functions.php

    r509 r510  
    229229}
    230230
    231 function get_calendar() {
    232     global $wpdb, $HTTP_GET_VARS, $m, $monthnum, $year, $timedifference, $month, $tableposts;
     231function get_calendar($daylength = 1) {
     232    global $wpdb, $HTTP_GET_VARS, $m, $monthnum, $year, $timedifference, $month, $weekday, $tableposts;
    233233// Quick check. If we have no posts at all, abort!
    234234if (!$posts) {
     
    269269                            FROM $tableposts
    270270                            WHERE post_date < '$thisyear-$thismonth-01'
     271                            AND post_status = 'publish'
    271272                            ORDER BY post_date DESC
    272273                            LIMIT 1");
    273274$next = $wpdb->get_row("SELECT  DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year
    274275                            FROM $tableposts
    275                             WHERE post_date >  '$thisyear-$thismonth-01' AND MONTH( post_date )  != MONTH( '$thisyear-$thismonth-01' )
     276                            WHERE post_date >  '$thisyear-$thismonth-01'
     277                            AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
     278                            AND post_status = 'publish'
    276279                            ORDER  BY post_date ASC
    277                             LIMIT 1 ");
     280                            LIMIT 1");
    278281
    279282echo '<table id="wp-calendar">
    280283    <caption>' . $month[zeroise($thismonth, 2)] . ' ' . date('Y', $unixmonth) . '</caption>
    281284<thead>
    282   <tr>
    283     <th abbr="Sunday" scope="col" title="Sunday">Sun</th>
    284     <th abbr="Monday" scope="col" title="Monday">Mon</th>
    285     <th abbr="Tuesday" scope="col" title="Tuesday">Tue</th>
    286     <th abbr="Wednesday" scope="col" title="Wednesday">Wed</th>
    287     <th abbr="Thursday" scope="col" title="Thursday">Thu</th>
    288     <th abbr="Friday" scope="col" title="Friday">Fri</th>
    289     <th abbr="Saturday" scope="col" title="Saturday">Sat</th>
    290   </tr>
     285  <tr>';
     286 foreach ($weekday as $wd) {
     287    echo "\n\t<th abbr='$wd' scope='col' title='$wd'>" . substr($wd, 0, $daylength) . '</th>';
     288 }
     289
     290echo '  </tr>
    291291</thead>
    292292
     
    295295
    296296if ($previous) {
    297     echo '<th abbr="' . $month[zeroise($previous->month, 2)] . '" colspan="3" id="prev"><a href="' .
     297    echo "\n\t".'<td abbr="' . $month[zeroise($previous->month, 2)] . '" colspan="3" id="prev"><a href="' .
    298298    get_month_link($previous->year, $previous->month) . '" title="View posts for ' . $month[zeroise($previous->month, 2)] . ' ' .
    299     date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)) . '">&laquo; ' . substr($month[zeroise($previous->month, 2)], 0, 3) . '</a>';
     299    date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)) . '">&laquo; ' . substr($month[zeroise($previous->month, 2)], 0, 3) . '</a></td>';
    300300} else {
    301     echo '<th colspan="3" id="prev">&laquo;</th>';
    302 }
    303 
    304 echo '<th>&nbsp;</th>';
     301    echo "\n\t".'<td colspan="3" id="prev">&laquo;</td>';
     302}
     303
     304echo "\n\t".'<td>&nbsp;</td>';
    305305
    306306if ($next) {
    307     echo '<th abbr="' . $month[zeroise($next->month, 2)] . '" colspan="3" id="next"><a href="' .
     307    echo "\n\t".'<td abbr="' . $month[zeroise($next->month, 2)] . '" colspan="3" id="next"><a href="' .
    308308    get_month_link($previous->year, $next->month) . '" title="View posts for ' . $month[zeroise($next->month, 2)] . ' ' .
    309     date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year)) . '">' . substr($month[zeroise($next->month, 2)], 0, 3) . ' &raquo;</a>';
     309    date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year)) . '">' . substr($month[zeroise($next->month, 2)], 0, 3) . ' &raquo;</a></td>';
    310310} else {
    311     echo '<th colspan="3" id="next">&raquo;</th>';
    312 }
    313 
    314 echo '  </tr>
     311    echo "\n\t".'<td colspan="3" id="next">&raquo;</td>';
     312}
     313
     314echo '
     315  </tr>
    315316</tfoot>
    316317
     
    324325                AND post_status = 'publish'
    325326                AND post_date < '" . date("Y-m-d H:i:s", (time() + ($time_difference * 3600)))."'", ARRAY_N);
    326 foreach ($dayswithposts as $daywith) {
    327     $daywithpost[] = $daywith[0];
     327
     328if ($dayswithposts) {
     329    foreach ($dayswithposts as $daywith) {
     330        $daywithpost[] = $daywith[0];
     331    }
     332} else {
     333    $daywithpost = array();
    328334}
    329335
    330336// See how much we should pad in the beginning
    331337$pad = intval(date('w', $unixmonth));
    332 if (0 != $pad) echo "\n\t<td class='empty' colspan='$pad'>&nbsp;</td>";
     338if (0 != $pad) echo "\n\t<td colspan='$pad'>&nbsp;</td>";
    333339
    334340$daysinmonth = intval(date('t', $unixmonth));
    335341for ($day = 1; $day <= $daysinmonth; ++$day) {
    336     if ($newrow) echo "\n</tr>\n  <tr>";
     342    if ($newrow) echo "\n  </tr>\n  <tr>\n\t";
    337343    $newrow = false;
    338     echo "\n\t<td>";
     344
     345    if ($day == date('j', (time() + ($time_difference * 3600)))) echo '<td id="today">';
     346    else echo "<td>";
    339347
    340348    if (in_array($day, $daywithpost)) {
Note: See TracChangeset for help on using the changeset viewer.