Make WordPress Core

Changeset 24


Ignore:
Timestamp:
05/21/2003 11:17:09 AM (22 years ago)
Author:
saxmatt
Message:

Added get_archives, tweaked comment_link.

File:
1 edited

Legend:

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

    r20 r24  
    111111}
    112112
     113function get_archives($type, $limit='') {
     114    global $tableposts, $dateformat, $time_difference, $siteurl, $blogfilename, $querystring_start, $querystring_equal, $month;
     115    // weekly and daily are *broken*
     116    dbconnect();
     117    if ('' != $limit) {
     118        $limit = (int) $limit;
     119        $limit= " LIMIT $limit";
     120    }
     121    // this is what will separate dates on weekly archive links
     122    $archive_week_separator = '–';
     123   
     124   
     125    // archive link url
     126    $archive_link_m = $siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal; # monthly archive
     127    $archive_link_w = $siteurl.'/'.$blogfilename.$querystring_start.'w'.$querystring_equal; # weekly archive
     128    $archive_link_p = $siteurl.'/'.$blogfilename.$querystring_start.'p'.$querystring_equal; # post-by-post archive
     129   
     130   
     131    $now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600)));
     132   
     133    if ($type == 'monthly') {
     134        $arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC" . $limit;
     135        $querycount++;
     136        $arc_result=mysql_query($arc_sql) or die($arc_sql.'<br />'.mysql_error());
     137        while($arc_row = mysql_fetch_array($arc_result)) {
     138            $arc_year  = $arc_row['YEAR(post_date)'];
     139            $arc_month = $arc_row['MONTH(post_date)'];
     140            echo "<li><a href=\"$archive_link_m$arc_year".zeroise($arc_month,2).'">';
     141            echo $month[zeroise($arc_month,2)].' '.$arc_year;
     142            echo "</a></li>\n";
     143        }
     144    } elseif ($type == 'daily') {
     145        $arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC" . $limit;
     146        $querycount++;
     147        $arc_result=mysql_query($arc_sql) or die($arc_sql.'<br />'.mysql_error());
     148        while($arc_row = mysql_fetch_array($arc_result)) {
     149            $arc_year  = $arc_row['YEAR(post_date)'];
     150            $arc_month = $arc_row['MONTH(post_date)'];
     151            $arc_dayofmonth = $arc_row['DAYOFMONTH(post_date)'];
     152            echo "<li><a href=\"$archive_link_m$arc_year".zeroise($arc_month,2).zeroise($arc_dayofmonth,2).'">';
     153            echo mysql2date($archive_day_date_format, $arc_year.'-'.zeroise($arc_month,2).'-'.zeroise($arc_dayofmonth,2).' 00:00:00');
     154            echo "</a></li>\n";
     155        }
     156    } elseif ($type == 'weekly') {
     157        if (!isset($start_of_week)) {
     158            $start_of_week = 1;
     159        }
     160        $arc_sql = "SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date), WEEK(post_date) FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC" . $limit;
     161        $querycount++;
     162        $arc_result=mysql_query($arc_sql) or die($arc_sql.'<br />'.mysql_error());
     163        $arc_w_last = '';
     164        while($arc_row = mysql_fetch_array($arc_result)) {
     165            $arc_year = $arc_row['YEAR(post_date)'];
     166            $arc_w = $arc_row['WEEK(post_date)'];
     167            if ($arc_w != $arc_w_last) {
     168                $arc_w_last = $arc_w;
     169                $arc_ymd = $arc_year.'-'.zeroise($arc_row['MONTH(post_date)'],2).'-' .zeroise($arc_row['DAYOFMONTH(post_date)'],2);
     170                $arc_week = get_weekstartend($arc_ymd, $start_of_week);
     171                $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
     172                $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
     173                echo "<li><a href=\"$siteurl/".$blogfilename."?m=$arc_year&amp;w=$arc_w\">";
     174                echo $arc_week_start.$archive_week_separator.$arc_week_end;
     175                echo "</a></li>\n";
     176            }
     177        }
     178    } elseif ($type == 'postbypost') {
     179        $requestarc = " SELECT ID,post_date,post_title FROM $tableposts WHERE post_date < '$now' AND post_category > 0 ORDER BY post_date DESC" . $limit;
     180        $querycount++;
     181        $resultarc = mysql_query($requestarc);
     182        while($row=mysql_fetch_object($resultarc)) {
     183            if ($row->post_date != '0000-00-00 00:00:00') {
     184                echo "<li><a href=\"$archive_link_p".$row->ID.'">';
     185                $arc_title = stripslashes($row->post_title);
     186                if ($arc_title) {
     187                    echo strip_tags($arc_title);
     188                } else {
     189                    echo $row->ID;
     190                }
     191                echo "</a></li>\n";
     192            }
     193        }
     194    }
     195}
    113196/***** // About-the-blog tags *****/
    114197
     
    871954}
    872955
    873 function comments_link($file='') {
     956function comments_link($file='',$echo=true) {
    874957    global $id,$pagenow;
    875958    global $querystring_start, $querystring_equal, $querystring_separator;
    876959    if ($file == '')    $file = $pagenow;
    877960    if ($file == '/')   $file = '';
    878     echo $file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'c'.$querystring_equal.'1#comments';
     961    if (!$echo) return $file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'c'.$querystring_equal.'1#comments';
     962    else echo $file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'c'.$querystring_equal.'1#comments';
    879963}
    880964
Note: See TracChangeset for help on using the changeset viewer.