viewing source for "fancy-archives-list.php"

last commit

commit 7780b7260c3088044dd3a52b28f15424a4e9f7e2 Author: root <root@a04a6e75-5819-0410-a511-8dafea38c924> Date: Thu Feb 8 00:05:13 2007 +0000
Added option to display pages with posts Modified everything to newest version number

source code

001: <?php
002: /*
003: Fancy Archives ver 0.5
004: Copyright 2006 Andrew Rader
005: 
006: This file is part of Fancy Archives
007: 
008: 	Fancy Archives is free software; you can redistribute it and/or modify
009: 	it under the terms of the GNU General Public License as published by
010: 	the Free Software Foundation; either version 2 of the License, or
011: 	(at your option) any later version.
012: 
013: 	Fancy Archives is distributed in the hope that it will be useful,
014: 	but WITHOUT ANY WARRANTY; without even the implied warranty of
015: 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016: 	GNU General Public License for more details.
017: 
018: 	You should have received a copy of the GNU General Public License
019: 	along with Fancy Archives; if not, write to the Free Software
020: 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
021: */
022: ?>
023: 
024: <ul id="fancy-archives-list">
025: <?php
026: global $wpdb, $month;
027: 
028: $now = current_time( 'mysql' );
029: 
030: $post_attrs = "post_date != '0000-00-00 00:00:00' AND post_status = 'publish'";
031: 
032: if( !fanarc::get_show_pages() ) {
033:     $post_attrs .= " AND post_type = 'post'";
034: }
035: 
036: $fancy_posts = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`,
037:         MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts
038:         WHERE post_date < '$now' AND $post_attrs GROUP BY YEAR(post_date),
039:         MONTH(post_date) ORDER BY post_date DESC");
040: 
041: if( $fancy_posts ) {
042:     $current_year = -1;
043:     $current_mont = -1;
044:     $new_year = false;
045:     $new_month = false;
046:     $close_previous_year = false;
047: 
048:     foreach( $fancy_posts as $fancy_post ) {
049:         $rel = "show";
050:         if( fanarc::get_expand_current_year()
051:                 && $fancy_post->year == date('Y') ) {
052:             $rel = "hide";
053:         }
054: 
055:         if( $current_year != $fancy_post->year
056:                 || $current_month != $fancy_post->month ) {
057:             $fancy_monthsposts = $wpdb->get_results("SELECT ID, post_title,
058:                     post_date FROM $wpdb->posts WHERE YEAR(post_date) = '
059:                     $fancy_post->year' AND MONTH(post_date) = '
060:                     $fancy_post->month' AND $post_attrs ORDER BY post_date 
061:                     DESC");
062:             $current_month = $fancy_post->month;
063:             $new_month = true;
064:         }
065: 
066:         if( $current_year != $fancy_post->year ) {
067:             $fancy_yearposts = $wpdb->get_results("SELECT ID, post_title, 
068:                     post_date FROM $wpdb->posts WHERE YEAR(post_date) = '
069:                     $fancy_post->year' AND $post_attrs");
070:             $current_year = $fancy_post->year;
071:             $new_year = true;
072:         }
073: 
074:         if( fanarc::get_show_year_count() && $fancy_yearposts ) {
075:             $year_count = ' ('.count( $fancy_yearposts ).')';
076:         }
077:         else {
078:             $year_count = '';
079:         }
080: 
081:         if( fanarc::get_show_month_count() && $fancy_monthsposts ) {
082:             $month_count = ' ('.count($fancy_monthsposts ).')';
083:         }
084:         else {
085:             $month_count = '';
086:         }
087: 
088:         if( $new_year ) {
089:             if( $close_previous_year ) {
090:                 echo "</ul></li>";
091:             }
092:             $close_previous_year = true;
093: 
094:             echo "<li>\n<a href=\"javascript:;\" onclick=\"";
095:             echo "hideNestedList(event); return false\" rel=\"$rel\">";
096:             echo "$current_year</a>$year_count\n";
097:             echo "<ul id=\"fancyArchivesList-$current_year\">\n";
098:             $new_year = false;
099:         }
100:         if( fanarc::get_show_months() ) {
101:             $text = sprintf('%s', $month[zeroise($current_month,2)]);
102: 
103:             $text = wptexturize($text);
104:             $title_text = wp_specialchars($text,1);
105: 
106:             if( fanarc::get_expand_months() ) {
107:                 $link = 'javascript:;';
108:                 $onclick = 'onclick="hideNestedList(event); return false"';
109:                 if( fanarc::get_expand_current_month()
110:                         && $current_year == date('Y')
111:                         && $current_month == date('n') ) {
112:                     $month_rel = 'rel="hide" ';
113:                 }
114:                 else {
115:                     $month_rel = 'rel="show" ';
116:                 }
117:             }
118:             else {
119:                 $link = get_month_link( $current_year, $current_month );
120:                 $onclick = '';
121:                 $month_rel = '';
122:             }
123:             $the_link = '<a href="'.$link.'" title="'.$title_text.'" ';
124:             $the_link .= $month_rel.$onclick.'>'.$text.'</a>';
125: 
126:             echo '<li>'.$the_link.$month_count;
127: 
128:             if( fanarc::get_show_months() && fanarc::get_expand_months() ) {
129:                 echo "<ul id=\"fancyArchivesList-";
130:                 echo "$current_year-$current_month\">\n";
131: 
132:                 foreach( $fancy_monthsposts as $fancy_post ) {
133:                     $text = '';
134: 
135:                     if( fanarc::get_show_post_number() ) {
136:                         $text .= '#'.$fancy_post->ID;
137:                     }
138: 
139:                     if( fanarc::get_show_post_title() ) {
140:                         $title_text = $fancy_post->post_title;
141: 
142:                         if( fanarc::get_post_title_length() > 0 && strlen( $title_text ) > fanarc::get_post_title_length() ) {
143:                             $title_text = substr( $title_text, 0, fanarc::get_post_title_length() );
144:                             if( fanarc::get_show_post_title_ellipsis() ) {
145:                                 $title_text .= ' ...';
146:                             }
147:                         }
148: 
149:                         $text .= ( $text == '' ? $title_text : ' - '.$title_text );
150:                     }
151: 
152:                     if( fanarc::get_show_post_date() ) {
153:                         $theDate = mysql2date( fanarc::get_post_date_format(), $fancy_post->post_date );
154:                         $text .= ( $text == '' ? $theDate : ', '.$theDate );
155:                     }
156: 
157:                     if( fanarc::get_show_comment_count() ) {
158:                         $commcount = ' ('.get_comments_number($fancy_post->ID).')';
159:                     }
160: 
161:                     $link = get_permalink( $fancy_post->ID );
162: 
163:                     echo "<li><a href=\"$link\" title=\"$fancy_post->post_title\">$text</a>$commcount</li>\n";
164:                 }
165:                 echo "</ul>\n";
166:             }
167:             echo "</li>\n";
168:         }
169:         else {
170:             foreach( $fancy_monthsposts as $fancy_post ) {
171:                 echo '<li>';
172:                 $text = '';
173: 
174:                 if( fanarc::get_show_post_number() ) {
175:                     $text .= '#'.$fancy_post->ID;
176:                 }
177: 
178:                 if( fanarc::get_show_post_title() ) {
179:                     $text .= ( $text == '' ? $fancy_post->post_title : ' - '.$fancy_post->post_title );
180:                 }
181: 
182:                 if( fanarc::get_show_post_date() ) {
183:                     $theDate = mysql2date( fanarc::get_post_date_format(), $fancy_post->post_date );
184:                     $text .= ( $text == '' ? $theDate : ', '.$theDate );
185:                 }
186: 
187:                 if( fanarc::get_show_comment_count() ) {
188:                     $commcount = ' ('.get_comments_number($fancy_post->ID).')';
189:                 }
190: 
191:                 $link = get_permalink( $fancy_post->ID );
192:                 echo '<a href="'.$link.'">'.$text.'</a>'.$commcount;
193:                 echo '</li>';
194:             }
195:         }
196:     }
197:     echo "</ul></li>\n";
198: } ?>
199: </ul>