Changeset 14483
- Timestamp:
- 05/06/2010 07:31:45 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/default-widgets.php
r14374 r14483 589 589 <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label> 590 590 <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /><br /> 591 <small><?php _e('(at most 15)'); ?></small></p>592 591 <?php 593 592 } … … 619 618 620 619 function flush_widget_cache() { 621 wp_cache_delete(' recent_comments', 'widget');620 wp_cache_delete('widget_recent_comments', 'widget'); 622 621 } 623 622 624 623 function widget( $args, $instance ) { 625 global $wpdb, $comments, $comment; 626 627 extract($args, EXTR_SKIP); 628 $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title'], $instance, $this->id_base); 629 if ( !$number = (int) $instance['number'] ) 630 $number = 5; 631 else if ( $number < 1 ) 632 $number = 1; 633 else if ( $number > 15 ) 634 $number = 15; 635 636 if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) { 637 $comments = $wpdb->get_results("SELECT $wpdb->comments.* FROM $wpdb->comments JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID WHERE comment_approved = '1' AND post_status = 'publish' ORDER BY comment_date_gmt DESC LIMIT 15"); 638 wp_cache_add( 'recent_comments', $comments, 'widget' ); 639 } 640 641 $comments = array_slice( (array) $comments, 0, $number ); 642 ?> 643 <?php echo $before_widget; ?> 644 <?php if ( $title ) echo $before_title . $title . $after_title; ?> 645 <ul id="recentcomments"><?php 646 if ( $comments ) : foreach ( (array) $comments as $comment) : 647 echo '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; 648 endforeach; endif;?></ul> 649 <?php echo $after_widget; ?> 650 <?php 624 global $comments, $comment; 625 626 $cache = wp_cache_get('widget_recent_comments', 'widget'); 627 628 if ( ! is_array( $cache ) ) 629 $cache = array(); 630 631 if ( isset( $cache[$args['widget_id']] ) ) { 632 echo $cache[$args['widget_id']]; 633 return; 634 } 635 636 extract($args, EXTR_SKIP); 637 $output = ''; 638 $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']); 639 640 if ( ! $number = (int) $instance['number'] ) 641 $number = 5; 642 else if ( $number < 1 ) 643 $number = 1; 644 645 $comments = get_comments(array('number' => $number)); 646 $output .= $before_widget; 647 if ( $title ) 648 $output .= $before_title . $title . $after_title; 649 650 $output .= '<ul id="recentcomments">'; 651 if ( $comments ) { 652 foreach ( (array) $comments as $comment) { 653 $output .= '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; 654 } 655 } 656 $output .= '</ul>'; 657 $output .= $after_widget; 658 659 echo $output; 660 $cache[$args['widget_id']] = $output; 661 wp_cache_set('widget_recent_comments', $cache, 'widget'); 651 662 } 652 663 … … 673 684 <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of comments to show:'); ?></label> 674 685 <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /><br /> 675 <small><?php _e('(at most 15)'); ?></small></p>676 686 <?php 677 687 }
Note: See TracChangeset
for help on using the changeset viewer.