Changeset 2508747
- Timestamp:
- 04/03/2021 07:08:46 PM (5 years ago)
- Location:
- collapsed-archives/trunk
- Files:
-
- 3 edited
-
collapsed-archives.php (modified) (11 diffs)
-
readme.txt (modified) (3 diffs)
-
style.css (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
collapsed-archives/trunk/collapsed-archives.php
r2080908 r2508747 4 4 Plugin URI: https://github.com/mpetroff/collapsed-archives-wp 5 5 Description: Adds a widget to display archive links using purely CSS-based collapsing. 6 Version: 1. 56 Version: 1.6 7 7 Author: Matthew Petroff 8 8 Author URI: https://mpetroff.net/ … … 19 19 * @type bool $show_post_count Whether to display the post count alongside the link. Default false. 20 20 * @type bool $use_triangles Whether to use triangles to indicate expansion instead of +/-. Default false. 21 * @type bool $use_decades Whether to collapse decades as well. Default false. 21 22 * @type bool $never_expand Whether to never expand for date (normally expands for current post). Default false. 22 23 * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'. … … 31 32 'show_post_count' => false, 32 33 'use_triangles' => false, 34 'use_decades' => false, 33 35 'never_expand' => false, 34 36 'order' => 'DESC', … … 53 55 } 54 56 55 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BYYEAR(post_date), MONTH(post_date) ORDER BY post_date $order";57 $query = "SELECT FLOOR(YEAR(post_date)/10)*10 AS `decade`, YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY FLOOR(YEAR(post_date)/10)*10, YEAR(post_date), MONTH(post_date) ORDER BY post_date $order"; 56 58 $key = md5( $query ); 57 59 $key = "wp_get_archives:$key:$last_changed"; … … 66 68 } 67 69 $output .= '"><ul>'; 68 70 71 $prev_decade = false; 69 72 $prev_year = false; 70 73 foreach ( (array) $results as $result ) { 74 if ( $r['use_decades'] && $prev_decade != $result->decade ) { 75 if ( $prev_decade !== false ) { 76 $output .= '</ul></li></ul></li>'; 77 $prev_year = false; // this is so that the year output does not append extra </ul></li> below 78 } 79 80 $decade_id = 'archive-decade-' . $result->decade; 81 82 $output .= '<li>'; 83 $output .= '<input type="checkbox" id="' . $decade_id . '"'; 84 if ( isset( $wp_query->post->ID ) ) { 85 if ( !$r['never_expand'] && ( ( $result->decade == floor(get_the_date('Y', $wp_query->post->ID)/10)*10 && !is_page() ) || ( is_page() && $result->decade == floor(date('Y')/10)*10 ) ) ) { 86 $output .= ' checked'; 87 } 88 } 89 $output .= '>'; 90 $output .= '<label for="' . $decade_id . '"></label>'; 91 92 $after = ''; 93 if ( $r['show_post_count'] ) { 94 $decade_args = array( 95 'date_query' => array( 96 array( 97 'after' => array( 98 'year' => $result->decade, 99 'month' => 1, 100 'day' => 1, 101 ), 102 'before' => array( 103 'year' => $result->decade + 9, 104 'month' => 12, 105 'day' => 31, 106 ), 107 'inclusive' => true, 108 ), 109 ), 110 'posts_per_page' => -1, 111 ); 112 $decade_query = new WP_Query( $decade_args ); 113 $after = ' (' . $decade_query->found_posts . ')'; 114 } 115 $output .= $result->decade . 's' . $after; 116 117 $output .= '<ul class="decade">'; 118 119 $prev_decade = $result->decade; 120 } 121 71 122 if ( $prev_year != $result->year ) { 72 123 if ( $prev_year !== false ) { 73 124 $output .= '</ul></li>'; 74 125 } 75 126 76 127 $year_id = 'archive-year-' . $result->year; 77 128 78 129 $output .= '<li>'; 79 130 $output .= '<input type="checkbox" id="' . $year_id . '"'; … … 85 136 $output .= '>'; 86 137 $output .= '<label for="' . $year_id . '"></label>'; 87 138 88 139 $url = get_year_link( $result->year ); 89 140 $after = ''; … … 93 144 } 94 145 $output .= get_archives_link( $url, $result->year, '', '', $after ); 95 96 $output .= '<ul >';97 146 147 $output .= '<ul class="year">'; 148 98 149 $prev_year = $result->year; 99 150 } 100 151 101 152 $url = get_month_link( $result->year, $result->month ); 102 153 /* translators: 1: month name */ … … 108 159 $output .= get_archives_link( $url, $text, 'html', '', $after ); 109 160 } 161 if ( $r['use_decades'] ) { 162 $output .= '</ul></li>'; 163 } 110 164 $output .= '</ul></li></ul></div>'; 111 165 } 112 166 113 167 return $output; 114 168 } // function get_collapsed_archives … … 128 182 129 183 public function widget( $args, $instance ) { 130 184 131 185 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base ); 132 186 $count = ! empty( $instance['count'] ) ? '1' : '0'; 133 187 $use_triangles = ! empty( $instance['use_triangles'] ) ? '1' : '0'; 188 $use_decades = ! empty( $instance['use_decades'] ) ? '1' : '0'; 134 189 $never_expand = ! empty( $instance['never_expand'] ) ? '1' : '0'; 135 190 $order = ! empty( $instance['asc_order'] ) ? 'ASC' : 'DESC'; 136 191 137 192 echo $args['before_widget']; 138 193 if ( $title ) { 139 194 echo $args['before_title'] . $title . $args['after_title']; 140 195 } 141 echo collapsed_archives_get_collapsed_archives( array( 'show_post_count' => $count, 'use_triangles' => $use_triangles, ' never_expand' => $never_expand, 'order' => $order ) );196 echo collapsed_archives_get_collapsed_archives( array( 'show_post_count' => $count, 'use_triangles' => $use_triangles, 'use_decades' => $use_decades, 'never_expand' => $never_expand, 'order' => $order ) ); 142 197 echo $args['after_widget']; 143 198 } … … 148 203 $count = $instance['count'] ? 'checked="checked"' : ''; 149 204 $use_triangles = $instance['use_triangles'] ? 'checked="checked"' : ''; 205 $use_decades = $instance['use_decades'] ? 'checked="checked"' : ''; 150 206 $never_expand = $instance['never_expand'] ? 'checked="checked"' : ''; 151 207 $asc_order = $instance['asc_order'] ? 'checked="checked"' : ''; 152 208 ?> 153 209 <p> 154 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />210 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /> 155 211 </p> 156 212 <p> 157 <input class="checkbox" type="checkbox" <?php echo $count; ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Show post counts'); ?></label> 158 <br/> 159 <input class="checkbox" type="checkbox" <?php echo $use_triangles; ?> id="<?php echo $this->get_field_id('use_triangles'); ?>" name="<?php echo $this->get_field_name('use_triangles'); ?>" /> <label for="<?php echo $this->get_field_id('use_triangles'); ?>"><?php _e('Use triangles to indicate expansion instead of +/-.'); ?></label> 160 <br/> 161 <input class="checkbox" type="checkbox" <?php echo $never_expand; ?> id="<?php echo $this->get_field_id('never_expand'); ?>" name="<?php echo $this->get_field_name('never_expand'); ?>" /> <label for="<?php echo $this->get_field_id('never_expand'); ?>"><?php _e('Don\'t expand list for current post / year.'); ?></label> 162 <br/> 163 <input class="checkbox" type="checkbox" <?php echo $asc_order; ?> id="<?php echo $this->get_field_id('asc_order'); ?>" name="<?php echo $this->get_field_name('asc_order'); ?>" /> <label for="<?php echo $this->get_field_id('asc_order'); ?>"><?php _e('Display archives in chronological order instead of reverse chronological order.'); ?></label> 213 <input class="checkbox" type="checkbox" <?php echo $count; ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Show post counts'); ?></label> 214 <br/> 215 <input class="checkbox" type="checkbox" <?php echo $use_triangles; ?> id="<?php echo $this->get_field_id('use_triangles'); ?>" name="<?php echo $this->get_field_name('use_triangles'); ?>" /> <label for="<?php echo $this->get_field_id('use_triangles'); ?>"><?php _e('Use triangles to indicate expansion instead of +/-.'); ?></label> 216 <br/> 217 <input class="checkbox" type="checkbox" <?php echo $use_decades; ?> id="<?php echo $this->get_field_id('use_decades'); ?>" name="<?php echo $this->get_field_name('use_decades'); ?>" /> <label for="<?php echo $this->get_field_id('use_decades'); ?>"><?php _e('Collapse decades.'); ?></label> 218 <br/> 219 <input class="checkbox" type="checkbox" <?php echo $never_expand; ?> id="<?php echo $this->get_field_id('never_expand'); ?>" name="<?php echo $this->get_field_name('never_expand'); ?>" /> <label for="<?php echo $this->get_field_id('never_expand'); ?>"><?php _e('Don\'t expand list for current post / year.'); ?></label> 220 <br/> 221 <input class="checkbox" type="checkbox" <?php echo $asc_order; ?> id="<?php echo $this->get_field_id('asc_order'); ?>" name="<?php echo $this->get_field_name('asc_order'); ?>" /> <label for="<?php echo $this->get_field_id('asc_order'); ?>"><?php _e('Display archives in chronological order instead of reverse chronological order.'); ?></label> 164 222 </p> 165 <?php 223 <?php 166 224 } 167 225 … … 172 230 $instance['count'] = $new_instance['count'] ? 1 : 0; 173 231 $instance['use_triangles'] = $new_instance['use_triangles'] ? 1 : 0; 232 $instance['use_decades'] = $new_instance['use_decades'] ? 1 : 0; 174 233 $instance['never_expand'] = $new_instance['never_expand'] ? 1 : 0; 175 234 $instance['asc_order'] = $new_instance['asc_order'] ? 1 : 0; 176 235 177 236 return $instance; 178 237 } -
collapsed-archives/trunk/readme.txt
r2386684 r2508747 3 3 Tags: archives, collapsed, collapsing, CSS 4 4 Requires at least: 2.8 5 Tested up to: 5. 5.16 Stable tag: 1. 55 Tested up to: 5.7.0 6 Stable tag: 1.6 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 20 20 * Option to never automatically expand list for current post / year 21 21 * Choice between displaying archive links in reverse chronological order or chronological order 22 * Decades can be collapsed 23 24 = 1.6 (2021-04-03) = 25 * Added support for collapsing decades (thanks to @PHil-PlainTech) 22 26 23 27 = 1.5 (2019-05-05) = … … 68 72 == Changelog == 69 73 74 = 1.6 (2021-04-03) = 75 * Added support for collapsing decades (thanks to @PHil-PlainTech) 76 70 77 = 1.5 (2019-05-05) = 71 78 * Fix for warning message in logs -
collapsed-archives/trunk/style.css
r1085312 r2508747 11 11 list-style: none !important; 12 12 margin-left: 0 !important; 13 } 14 .collapsed-archives > ul > li > .decade { 15 list-style: none !important; 16 margin-left: 1.25em !important; 13 17 } 14 18 .collapsed-archives ul ul {
Note: See TracChangeset
for help on using the changeset viewer.