Make WordPress Core

Changeset 509


Ignore:
Timestamp:
11/03/2003 04:14:54 PM (23 years ago)
Author:
saxmatt
Message:

Added get_day_link() and polished calendar, it now links days.

File:
1 edited

Legend:

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

    r508 r509  
    230230
    231231function get_calendar() {
     232        global $wpdb, $HTTP_GET_VARS, $m, $monthnum, $year, $timedifference, $month, $tableposts;
    232233// Quick check. If we have no posts at all, abort!
    233234if (!$posts) {
    … …  
    306307        echo '<th abbr="' . $month[zeroise($next->month, 2)] . '" colspan="3" id="next"><a href="' .
    307308        get_month_link($previous->year, $next->month) . '" title="View posts for ' . $month[zeroise($next->month, 2)] . ' ' .
    308         date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year)) . '">&raquo; ' . substr($month[zeroise($next->month, 2)], 0, 3) . '</a>';
     309        date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year)) . '">' . substr($month[zeroise($next->month, 2)], 0, 3) . ' &raquo;</a>';
    309310} else {
    310311        echo '<th colspan="3" id="next">&raquo;</th>';
    … …  
    319320// Get days with posts
    320321$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
    321                                 FROM wp_posts WHERE MONTH(post_date) = $thismonth
     322                                FROM $tableposts WHERE MONTH(post_date) = $thismonth
    322323                                AND YEAR(post_date) = $thisyear
    323324                                AND post_status = 'publish'
    324                                 AND post_date < '" . date("Y-m-d H:i:s", (time() + ($time_difference * 3600))), ARRAY_N);
    325 
    326 // TODO: Make days with posts linked
     325                                AND post_date < '" . date("Y-m-d H:i:s", (time() + ($time_difference * 3600)))."'", ARRAY_N);
     326foreach ($dayswithposts as $daywith) {
     327        $daywithpost[] = $daywith[0];
     328}
    327329
    328330// See how much we should pad in the beginning
    … …  
    334336        if ($newrow) echo "\n</tr>\n  <tr>";
    335337        $newrow = false;
    336         echo "\n\t<td>$day</td>";
     338        echo "\n\t<td>";
     339
     340        if (in_array($day, $daywithpost)) {
     341                echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\">$day</a>";
     342        } else {
     343                echo $day;
     344        }
     345
     346        echo '</td>';
    337347        if (6 == date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))) $newrow = true;
    338348}
    … …  
    399409                return $monthlink;
    400410        } else {
    401                 return $siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal.$year.$month;
     411                return $siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2);
     412        }
     413}
     414
     415function get_day_link($year, $month, $day) {
     416        global $siteurl, $blogfilename, $querystring_start, $querystring_equal;
     417        if (!$year) $year = date('Y', time()+($time_difference * 3600));
     418        if (!$month) $month = date('m', time()+($time_difference * 3600));
     419        if (!$day) $day = date('j', time()+($time_difference * 3600));
     420        if ('' != get_settings('permalink_structure')) {
     421                $off = strpos(get_settings('permalink_structure'), '%day%');
     422                $offset = $off + 6;
     423                $daylink = substr(get_settings('permalink_structure'), 0, $offset);
     424                if ('/' != substr($daylink, -1)) $daylink = substr($daylink, 0, -1);
     425                $daylink = str_replace('%year%', $year, $daylink);
     426                $daylink = str_replace('%monthnum%', intval($month), $daylink);
     427                $daylink = str_replace('%day%', intval($day), $daylink);
     428                return $daylink;
     429        } else {
     430                return $siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2).zeroise($day, 2);
    402431        }
    403432}
Note: See TracChangeset for help on using the changeset viewer.