__( 'The tags from the latest posts.', 'p2' ))); $this->default_num_to_show = 35; } function form( $instance ) { $title = ( isset( $instance['title'] ) ) ? esc_attr( $instance['title'] ) : ''; $title_id = $this->get_field_id( 'title' ); $title_name = $this->get_field_name( 'title' ); $num_to_show = ( isset( $instance['num_to_show'] ) ) ? esc_attr( $instance['num_to_show'] ) : $this->default_num_to_show; $num_to_show_id = $this->get_field_id( 'num_to_show' ); $num_to_show_name = $this->get_field_name( 'num_to_show' ); ?>

default_num_to_show; return $new_instance; } function widget( $args, $instance ) { extract( $args ); $title = (isset( $instance['title'] ) && $instance['title'])? $instance['title'] : __( 'Recent tags', 'p2' ); $num_to_show = (isset( $instance['num_to_show'] ) && (int)$instance['num_to_show'])? (int)$instance['num_to_show'] : $this->default_num_to_show; $recent_tags = $this->recent_tags( $num_to_show ); echo $before_widget . $before_title . esc_html( $title ) . $after_title; echo "\t 'all' ) ); $post_ids_and_tags = array(); foreach( $all_tags as $tag ) { if ( $tag->count < 1 ) continue; $recent_post_id = max( get_objects_in_term( $tag->term_id, 'post_tag' ) ); $post_ids_and_tags[] = array( 'post_id' => $recent_post_id, 'tag' => $tag ); } usort( $post_ids_and_tags, function($a, $b) { return $b["post_id"] - $a["post_id"]; }); $post_ids_and_tags = array_slice( $post_ids_and_tags, 0, $num_to_show ); $recent_tags = array(); foreach( $post_ids_and_tags as $v ) { $recent_tags[] = array( 'tag' => $v['tag'], 'link' => get_tag_link( $v['tag']->term_id ), 'feed_link' => get_tag_feed_link( $v['tag']->term_id ), ); } $cache[$num_to_show] = $recent_tags; wp_cache_add( 'p2_recent_tags', $cache, 'widget' ); return $recent_tags; } } register_widget( 'P2_Recent_Tags' );