Changeset 459937
- Timestamp:
- 11/06/2011 02:16:51 PM (14 years ago)
- Location:
- norman-advanced-archive-widget/trunk
- Files:
-
- 2 edited
-
norman-adv-archive.php (modified) (8 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
norman-advanced-archive-widget/trunk/norman-adv-archive.php
r458720 r459937 19 19 Description: Norman Advanced Archive Widget is a free replacement for the standard WordPress archive widget. Lots of customization options to satisfy your needs. 20 20 Author: Andreas Norman 21 Version: 1. 021 Version: 1.1 22 22 Author URI: http://www.andreasnorman.se 23 23 */ … … 29 29 } 30 30 31 function get_years() { 31 function get_years($current_category_id) { 32 global $wpdb; 33 34 if ($current_category_id) { 35 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN ($current_category_id)"); 36 $join = apply_filters('getarchives_join', " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"); 37 } else { 38 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'"); 39 $join = apply_filters('getarchives_join', ""); 40 } 41 42 $sql = "SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts "; 43 $sql .="FROM {$wpdb->posts} {$join} {$where} "; 44 $sql .="GROUP BY YEAR(post_date) ORDER BY post_date DESC"; 45 46 return $wpdb->get_results($sql); 47 } 48 49 function get_months($year, $current_category_id) { 32 50 global $wpdb; 33 51 34 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'"); 35 $join = apply_filters('getarchives_join', ""); 36 37 $sql = "SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts "; 38 $sql .="FROM {$wpdb->posts} {$join} {$where} "; 39 $sql .="GROUP BY YEAR(post_date) ORDER BY post_date DESC"; 40 41 return $wpdb->get_results($sql); 42 } 43 44 function get_months($year) { 45 global $wpdb; 46 47 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = {$year}"); 48 $join = apply_filters('getarchives_join', ""); 52 if ($current_category_id) { 53 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = {$year} AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN ($current_category_id)"); 54 $join = apply_filters('getarchives_join', " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"); 55 } else { 56 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = {$year}"); 57 $join = apply_filters('getarchives_join', ""); 58 } 49 59 50 60 $sql = "SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts "; … … 55 65 } 56 66 57 function get_posts($year, $month) { 58 global $wpdb; 59 60 if (empty($year) || empty($month)) 61 return null; 62 67 function get_posts($year, $month, $current_category_id) { 68 global $wpdb; 69 70 if (empty($year) || empty($month)) 71 return null; 72 73 if ($current_category_id) { 74 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = {$year} AND MONTH(post_date) = {$month} AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN ($current_category_id)"); 75 $join = apply_filters('getarchives_join', " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"); 76 } else { 63 77 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = {$year} AND MONTH(post_date) = {$month}"); 64 78 $join = apply_filters('getarchives_join', ""); 65 66 $sql = "SELECT ID, post_title, post_name FROM {$wpdb->posts} "; 67 $sql .="$join $where ORDER BY post_date DESC"; 68 69 return $wpdb->get_results($sql); 79 } 80 81 $sql = "SELECT ID, post_title, post_name FROM {$wpdb->posts} "; 82 $sql .="$join $where ORDER BY post_date DESC"; 83 84 return $wpdb->get_results($sql); 70 85 } 71 86 … … 79 94 $jsexpand = empty($instance['jsexpand']) ? 0 : $instance['jsexpand']; 80 95 $groupbyyear = empty($instance['groupbyyear']) ? 0 : $instance['groupbyyear']; 96 $limitbycategory = empty($instance['limitbycategory']) ? 0 : $instance['limitbycategory']; 97 #$hideonnoncategory = empty($instance['hideonnoncategory']) ? 0 : $instance['hideonnoncategory']; 81 98 $title = empty($instance['title']) ? 'Archive' : $instance['title']; 99 100 if ($limitbycategory) { 101 $current_category_id = get_query_var('cat'); 102 } else { 103 $current_category_id = false; 104 } 105 82 106 if ($jsexpand == 1) { 83 107 $groupbyyear = 1; 84 108 } 85 86 $years = $this->get_years(); 109 if ($groupbyyear == 1) { 110 $jsexpand = 1; 111 } 112 113 $years = $this->get_years($current_category_id); 87 114 $post_year = $years[0]->year; 88 115 … … 92 119 for ($i = 0; $x < count($years[$i]); $i++) { 93 120 $this_year = $jal_options['expandcurrent'] && $years[$i]->year == $post_year; 94 $months = $this->get_months($years[$i]->year );121 $months = $this->get_months($years[$i]->year, $current_category_id); 95 122 96 123 if ($groupbyyear) { … … 167 194 $instance['jsexpand'] = strip_tags($new_instance['jsexpand']); 168 195 $instance['groupbyyear'] = strip_tags($new_instance['groupbyyear']); 196 $instance['limitbycategory'] = strip_tags($new_instance['limitbycategory']); 197 #$instance['hideonnoncategory'] = strip_tags($new_instance['hideonnoncategory']); 169 198 170 199 return $instance; … … 178 207 $jsexpand = empty($instance['jsexpand']) ? 0 : esc_attr($instance['jsexpand']); 179 208 $groupbyyear = empty($instance['groupbyyear']) ? 0 : esc_attr($instance['groupbyyear']); 209 $limitbycategory = empty($instance['limitbycategory']) ? 0 : esc_attr($instance['limitbycategory']); 210 #$hideonnoncategory = empty($instance['hideonnoncategory']) ? 0 : esc_attr($instance['hideonnoncategory']); 211 180 212 if ($jsexpand == 1) { 181 213 $groupbyyear = 1; … … 191 223 192 224 <p> 193 <label for="<?php echo $this->get_field_id('groupbyyear'); ?>"><?php _e('Group By Year (Collaps list):'); ?></label> 225 <input <?php echo ($limitbycategory=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('limitbycategory'); ?>" name="<?php echo $this->get_field_name('limitbycategory'); ?>" type="checkbox" value="1" /> 226 <label for="<?php echo $this->get_field_id('limitbycategory'); ?>"><?php _e('Limit to current category'); ?></label> 227 </p> 228 229 <!-- 230 <p> 231 <input <?php echo ($hideonnoncategory=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('hideonnoncategory'); ?>" name="<?php echo $this->get_field_name('hideonnoncategory'); ?>" type="checkbox" value="1" /> 232 <label for="<?php echo $this->get_field_id('hideonnoncategory'); ?>"><?php _e('Hide on none category pages'); ?></label> 233 </p> 234 --> 235 <p> 194 236 <input <?php echo ($groupbyyear=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('groupbyyear'); ?>" name="<?php echo $this->get_field_name('groupbyyear'); ?>" type="checkbox" value="1" /> 195 </p>196 197 <p> 198 <label for="<?php echo $this->get_field_id('jsexpand'); ?>"><?php _e('Collaps list (Groups by year):'); ?></label>237 <label for="<?php echo $this->get_field_id('groupbyyear'); ?>"><?php _e('Group By Year (Collaps list)'); ?></label> 238 </p> 239 240 <p> 199 241 <input <?php echo ($jsexpand=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('jsexpand'); ?>" name="<?php echo $this->get_field_name('jsexpand'); ?>" type="checkbox" value="1" /> 200 </p>201 202 <p> 203 <label for="<?php echo $this->get_field_id('showcount'); ?>"><?php _e('Show Count:'); ?></label>242 <label for="<?php echo $this->get_field_id('jsexpand'); ?>"><?php _e('Collaps list (Groups by year)'); ?></label> 243 </p> 244 245 <p> 204 246 <input <?php echo ($showcount=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('showcount'); ?>" name="<?php echo $this->get_field_name('showcount'); ?>" type="checkbox" value="1" /> 205 </p>206 207 <p> 208 <label for="<?php echo $this->get_field_id('linkcounter'); ?>"><?php _e('Include count in link:'); ?></label>247 <label for="<?php echo $this->get_field_id('showcount'); ?>"><?php _e('Show Count'); ?></label> 248 </p> 249 250 <p> 209 251 <input <?php echo ($linkcounter=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('linkcounter'); ?>" name="<?php echo $this->get_field_name('linkcounter'); ?>" type="checkbox" value="1" /> 210 </p>211 212 <p> 213 <label for="<?php echo $this->get_field_id('truncmonth'); ?>"><?php _e('Truncate month name:'); ?></label>252 <label for="<?php echo $this->get_field_id('linkcounter'); ?>"><?php _e('Include count in link'); ?></label> 253 </p> 254 255 <p> 214 256 <input <?php echo ($truncmonth=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('truncmonth'); ?>" name="<?php echo $this->get_field_name('truncmonth'); ?>" type="checkbox" value="1" /> 257 <label for="<?php echo $this->get_field_id('truncmonth'); ?>"><?php _e('Truncate month name'); ?></label> 215 258 </p> 216 259 -
norman-advanced-archive-widget/trunk/readme.txt
r458720 r459937 15 15 = Features: = 16 16 17 * Group monthly archives by year 17 * Option to limit display of archive by current category. Only the posts in the current category will be listed 18 * Option to group monthly archives by year 18 19 * JQuery powered fold to show and hide monthly archives in a year. 19 20 * Option to truncate month names or not. 20 * Show/Hide archive count and the design option to decide if you want the count to be displayed inside the link or not.21 * Option to show/hide archive count and the design option to decide if you want the count to be displayed inside the link or not. 21 22 22 23 == Installation == … … 38 39 == Changelog == 39 40 41 = 1.1 = 42 New feature 43 * Option to limit display of archive by current category. Only the posts in the current category will be listed 44 40 45 = 1.0 = 41 46 Initial release
Note: See TracChangeset
for help on using the changeset viewer.