defaults = array( 'title' => esc_attr__( 'Archives', 'essential-widgets' ), 'limit' => 10, 'type' => 'monthly', 'post_type' => 'post', 'order' => 'DESC', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, ); $widget_ops = array( 'classname' => 'essential-widgets widget_archive ew-archive ewarchive', 'description' => esc_html__( 'Displays a list of categories', 'essential-widgets' ), ); $control_ops = array( 'id_base' => 'ew-archive', ); parent::__construct( 'ew-archive', // Base ID __( 'EW: Archives', 'essential-widgets' ), // Name $widget_ops, $control_ops ); } public function form( $instance ) { // Merge the user-selected arguments with the defaults. $instance = wp_parse_args( (array) $instance, $this->defaults ); // Get post types. $post_types = get_post_types( array( 'name' => 'post' ), 'objects' ); $post_types = array_merge( $post_types, get_post_types( array( 'publicly_queryable' => true, '_builtin' => false, ), 'objects' ) ); // Create an array of archive types. $type = array( 'alpha' => esc_attr__( 'Alphabetical', 'essential-widgets' ), 'daily' => esc_attr__( 'Daily', 'essential-widgets' ), 'monthly' => esc_attr__( 'Monthly', 'essential-widgets' ), 'postbypost' => esc_attr__( 'Post By Post', 'essential-widgets' ), 'weekly' => esc_attr__( 'Weekly', 'essential-widgets' ), 'yearly' => esc_attr__( 'Yearly', 'essential-widgets' ), ); // Create an array of order options. $order = array( 'ASC' => esc_attr__( 'Ascending', 'essential-widgets' ), 'DESC' => esc_attr__( 'Descending', 'essential-widgets' ), ); // Create an array of archive formats. $format = array( 'custom' => esc_attr__( 'Plain', 'essential-widgets' ), 'html' => esc_attr__( 'List', 'essential-widgets' ), 'option' => esc_attr__( 'Dropdown', 'essential-widgets' ), ); ?>

defaults ); // Output the sidebar's $before_widget wrapper. echo $args['before_widget']; // If a title was input by the user, display it. if ( ! empty( $instance['title'] ) ) { echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; } echo $this->shortcode( $instance ); // Close the sidebar's widget wrapper. echo $args['after_widget']; } public function shortcode( $atts ) { // Overwrite the $echo argument and set it to false. $atts['echo'] = false; $class = ''; // Get the archives list. $archives = str_replace( array( "\r", "\n", "\t" ), '', wp_get_archives( $atts ) ); $archives = str_replace( ' (', ' (', $archives ); $archives = str_replace( ')', ')', $archives ); // return $archives; $dropdown_id = esc_attr( uniqid( 'wp-block-archives-' ) ); $ew_archives = ''; // Only show this title in block element and not on widget. if ( isset( $atts['is_block'] ) && true === $atts['is_block'] && !empty( $atts['title'] ) ) { $ew_archives .= '

' . $atts['title'] . '

'; } // If the archives should be shown in a ' . $archives . ''; // return 'hello'; $ew_archives .= sprintf( '
%2$s
', esc_attr( $class ), $block_content ); return $ew_archives; // Output the '; $ew_archive .= ''; $ew_archive .= $archives; $ew_archive .= ''; */ } // If the format should be an unordered list. elseif ( 'html' == $atts['format'] ) { $ew_archives .= ''; } // All other formats. elseif ( 'custom' == $atts['format'] ) { $ew_archives .= $archives; } return $ew_archives; } } // end Archive_Widget class endif; if ( ! function_exists( 'ew_archives_register' ) ) : /** * Intiate Archive_Widget Class. * * @since 1.0.0 */ function ew_archives_register() { register_widget( 'EW_Archives' ); } add_action( 'widgets_init', 'ew_archives_register' ); endif;