Changeset 1232717
- Timestamp:
- 08/28/2015 12:55:55 AM (11 years ago)
- Location:
- category-monthly-archives/trunk
- Files:
-
- 3 edited
-
category-monthly-archives.php (modified) (1 diff)
-
class-category-monthly-archives.php (modified) (15 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
category-monthly-archives/trunk/category-monthly-archives.php
r1231700 r1232717 2 2 /* 3 3 Plugin Name: Category Monthly Archives 4 Version: 0.0. 14 Version: 0.0.2 5 5 Description: This widget display monthly archive links on category archives page. 6 6 Author: Hiroshi Sawai -
category-monthly-archives/trunk/class-category-monthly-archives.php
r1231698 r1232717 1 1 <?php 2 /** 3 * Category Monthly Archives Widget class file 4 */ 2 5 3 6 /** 4 7 * Category Monthly Archives Widget 5 *6 8 * This Widget displays category monthly archives links on category page. 7 9 * Only displays links on category page. 8 *9 10 */ 10 11 class CategoryMonthlyArchives extends WP_Widget … … 13 14 * Setting widget 14 15 */ 15 function __construct() 16 { 16 function __construct() { 17 17 $widget_ops = array( 18 18 'description' => __( 19 19 'Displays monthly archives link on category page.', 20 20 'cmarchives' 21 ) 21 ), 22 22 ); 23 23 parent::__construct( … … 30 30 /** 31 31 * Display setting form on admin page. 32 *33 32 * @param object $instance received from WordPress. 34 33 */ 35 function form( $instance ) 36 { 34 function form( $instance ) { 37 35 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0 ) ); 38 36 $title = sanitize_text_field( $instance['title'] ); … … 41 39 <p> 42 40 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"> 43 <?php _e( 'Title:', 'cmarchives' ); ?>41 <?php esc_html_e( 'Title:', 'cmarchives' ); ?> 44 42 </label> 45 43 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" … … 48 46 </p> 49 47 <p> 50 <input class="checkbox" type="checkbox" <?php echo $count; ?>48 <input class="checkbox" type="checkbox" <?php echo esc_attr( $count ); ?> 51 49 id="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>" 52 50 name="<?php echo esc_attr( $this->get_field_name( 'count' ) ); ?>"/> 53 51 <label for="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>"> 54 <?php _e( 55 'Show post counts', 56 'cmarchives' 57 ); ?> 52 <?php esc_html_e( 'Show post counts', 'cmarchives' ); ?> 58 53 </label> 59 54 </p> … … 63 58 /** 64 59 * Save widget form setting. 65 *66 60 * @param object $new_instance received from WordPress. 67 61 * @param object $old_instance received from WordPress. 68 62 */ 69 function update( $new_instance, $old_instance ) 70 { 63 function update( $new_instance, $old_instance ) { 71 64 $instance = $old_instance; 72 65 $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0 ) ); … … 82 75 * @param object $instance received from WordPress. 83 76 */ 84 function widget( $args, $instance ) 85 { 77 function widget( $args, $instance ) { 86 78 global $wp_query; 87 79 … … 96 88 $this->id_base 97 89 ); 98 // get category id99 $cat_id = $wp_query->query_vars[ "cat"];100 101 // display category monthly archives link90 // Get category id. 91 $cat_id = $wp_query->query_vars['cat']; 92 93 // Display category monthly archives link. 102 94 echo $args['before_widget']; 103 95 if ( ! empty( $title ) ) { … … 120 112 </ul> 121 113 <?php 122 echo $args["after_widget"]; 123 } 124 125 /** 126 * Get archives markup 127 * 128 * customize wp-includes/general-template.php -> wp_get_archives 129 * 130 * @param integer $cat_id Category ID. 114 echo $args['after_widget']; 115 } 116 117 /** 118 * Get archives markup. 119 * 120 * Customize wp-includes/general-template.php -> wp_get_archives 121 * 131 122 * @param string|array $args Optional. Override defaults. 132 123 * @return string|null String when retrieving, null when displaying. 133 124 */ 134 private function get_archives( $args = '' ) 135 { 125 private function get_archives( $args = '' ) { 136 126 global $wpdb; 137 127 138 // get category id128 // Get category id 139 129 $cat_id = (int) $args['cat_id']; 140 130 … … 147 137 'show_post_count' => false, 148 138 'echo' => 1, 149 'order' => 'DESC' 139 'order' => 'DESC', 150 140 ); 151 141 … … 161 151 162 152 $order = strtoupper( $r['order'] ); 163 if ( $order !== 'ASC') {153 if ( 'ASC' !== $order ) { 164 154 $order = 'DESC'; 165 155 } … … 170 160 $r 171 161 ); 172 $custom_sql = "LEFT JOIN $wpdb->term_relationships AS r ON $wpdb->posts.ID = r.object_ID" 173 . " LEFT JOIN $wpdb->term_taxonomy AS t ON r.term_taxonomy_id = t.term_taxonomy_id" 174 . " LEFT JOIN $wpdb->terms as terms ON t.term_id = terms.term_id"; 162 $custom_sql = "LEFT JOIN $wpdb->term_relationships AS r ON $wpdb->posts.ID = r.object_ID LEFT JOIN $wpdb->term_taxonomy AS t ON r.term_taxonomy_id = t.term_taxonomy_id LEFT JOIN $wpdb->terms as terms ON t.term_id = terms.term_id"; 175 163 $join = apply_filters( 'getarchives_join', $custom_sql, $r ); 176 164 177 165 $output = ''; 178 166 167 $last_changed = wp_cache_get( 'last_changed', 'posts' ); 168 if ( ! $last_changed ) { 169 $last_changed = microtime(); 170 wp_cache_set( 'last_changed', $last_changed, 'posts' ); 171 } 172 179 173 if ( 'monthly' === $type ) { 180 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) AS posts " 181 . "FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) " 182 . "ORDER BY post_date $order $limit"; 183 $results = $wpdb->get_results( $query ); 174 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) AS posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit"; 175 $key = md5( $query ); 176 $key = "wp_get_archives:$key:$last_changed"; 177 if ( ! $results = wp_cache_get( $key, 'posts' ) ) { 178 $results = $wpdb->get_results( $query ); 179 wp_cache_set( $key, $results, 'posts' ); 180 } 184 181 if ( ! empty( $results ) ) { 185 182 $afterafter = $r['after']; … … 205 202 * Get link. 206 203 * 207 * refer wp-includes/link-template.php->get_month_link204 * Refer wp-includes/link-template.php->get_month_link 208 205 * 209 206 * @param bool|int $year False for current year. Integer of year. … … 215 212 * @since 1.0.0 216 213 */ 217 private function get_link( $year, $month, $cat_id ) 218 { 214 private function get_link( $year, $month, $cat_id ) { 219 215 global $wp_rewrite; 220 216 … … 225 221 $month = gmdate( 'm', current_time( 'timestamp' ) ); 226 222 } 227 // get monthly link223 // Get monthly link. 228 224 $month_link = $wp_rewrite->get_month_permastruct(); 229 225 if ( ! empty( $month_link ) ) { 230 226 $month_link = str_replace( '%year%', $year, $month_link ); 231 227 $month_link = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $month_link ); 232 // add category id to query parameter228 // Add category id to query parameter. 233 229 return apply_filters( 234 230 'month_link', -
category-monthly-archives/trunk/readme.txt
r1231698 r1232717 5 5 Requires at least: 4.3 6 6 Tested up to: 4.3 7 Stable tag: 0.0. 17 Stable tag: 0.0.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.