__( 'Archive Widget to Categorize the archives date wise as well as category wise.', 'archives-category-date' ) ) ); } /** * Function retrives date, months from url and displays archives link * * @param array $args Consisting date as well as category name. * @param array $instance Filters posts by given parameters. * @since 1.0.0 */ public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); echo $args['before_widget']; if ( ! empty( $title ) ) { echo '

'.esc_attr( $title ).'

'.$args['after_title']; } $month_slug_type = get_archives_category_date_month_slug_type(); $cats = get_categories(); // Loop through the categries. foreach ( $cats as $cat ) { // Setup the cateogory ID. $cat_id = $cat->term_id; $args = array( 'cat' => $cat_id, 'posts_per_page' => -1 ); $query = new WP_Query( $args ); // Start the wordpress loop! if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); if ( 'numeric' === $month_slug_type ) { $month_slug = get_the_time( __( 'm', 'archives-category-date' ) ); } else { $month_slug = get_the_time( __( 'M', 'archives-category-date' ) ); } $catarrays[] = $cat_id; $arrays[] = $cat_id.'_'.get_the_time( __( 'Y', 'archives-category-date' ) ).'-'. $month_slug; endwhile; endif; wp_reset_postdata(); } // Done the foreach statement. $cat_arrays = array_unique( $catarrays ); // Unique array consisting all the categories ID. $unique_arrays = array_unique( $arrays ); // Unique strings of categories id, archive month & year. $val = null; echo '