diff --git a/cat-posts.php b/cat-posts.php index bd37d4a..478c5bc 100644 --- a/cat-posts.php +++ b/cat-posts.php @@ -170,6 +170,8 @@ function register_virtual_widgets() { */ function admin_scripts( $hook ) { + wp_enqueue_script('jquery-ui-datepicker'); + if ( 'widgets.php' === $hook ) { // enqueue only for widget admin and customizer. // control open and close the widget section. @@ -279,7 +281,12 @@ function admin_styles() { padding:0; cursor: pointer; } - +ul.categories-select{ + border: 5px solid #c00; +} +ul.categories-select ul.children{ + margin-left: 24px; +} array( + array( + 'after' => $instance['date_period_from'], + 'before' => $instance['date_period_to'], + ) + ) + ) + ); + } + return $args; } @@ -1131,7 +1166,7 @@ public function itemHTML( $instance, $current_post_id ) { $thumb_flex = explode( '%thumb%', $template ); if( count( $thumb_flex ) == 1) { $template = '
%thumb%
' . $thumb_flex[0] . '
'; - } + } if( count( $thumb_flex ) == 2) { $template = $thumb_flex[0] . '
%thumb%
' . $thumb_flex[1] . '
'; } @@ -1389,13 +1424,20 @@ public function formTitlePanel( $instance ) { public function formFilterPanel( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'cat' => 0 ) ); $cat = $instance['cat']; + $walker = new Walker_Category_Checklist_Radiobuttons( + $this->get_field_name( 'cat' ), + $this->get_field_id( 'cat' ) + ); ?>

-

get_number_input_block_html( $instance, 'num', esc_html__( 'Number of posts to show', 'category-posts' ), get_option( 'posts_per_page' ), 1, '', '', true ); echo $this->get_number_input_block_html( $instance, 'offset', esc_html__( 'Start with post', 'category-posts' ), 1, 1, '', '', true ); + + echo $this->get_text_date_block_html( $instance, 'date_period_from', esc_html__( 'Posts since', 'category-posts' ), '', '', true ); + echo $this->get_text_date_block_html( $instance, 'date_period_to', esc_html__( 'Posts to', 'category-posts' ), '', '', true ); + echo $this->get_select_block_html( $instance, 'sort_by', esc_html__( 'Sort by', 'category-posts' ), array( 'date' => esc_html__( 'Date', 'category-posts' ), 'title' => esc_html__( 'Title', 'category-posts' ), @@ -1556,6 +1604,52 @@ private function get_text_input_block_html( $instance, $key, $label, $default, $ return $this->get_wrap_block_html( $ret, $key, $visible ); } + + /** + * Generate a form P element containing a text input with datepicker + * + * @since 4.8.3 + * @param array $instance The instance. + * @param string $key The key in the instance array. + * @param string $label The label to display and associate with the input. + * Should be html escaped. + * @param int $default The value to use if the key is not set in the instance. + * @param string $placeholder The placeholder to use in the input. should be attribute escaped. + * @param bool $visible Indicates if the element should be visible when rendered. + * + * @return string HTML a P element contaning the input, its label, class based on the key + * and style set to display:none if visibility is off. + */ + private function get_text_date_block_html( $instance, $key, $label, $default, $placeholder, $visible ) { + + $value = $default; + + if ( isset( $instance[ $key ] ) ) { + $value = $instance[ $key ]; + } + + $ret = '\n"; + + $ret .= ''; + + return $this->get_wrap_block_html( $ret, $key, $visible ); + } + + /** * Generate a form P element containing a number input * @@ -1652,6 +1746,8 @@ public function form( $instance ) { 'excerpt_filters' => '', 'date' => '', 'date_format' => '', + 'date_period_from' => '', + 'date_period_to' => '', 'disable_css' => '', 'disable_font_styles' => '', 'hide_if_empty' => '', @@ -1671,6 +1767,8 @@ public function form( $instance ) { $excerpt_filters = $instance['excerpt_filters']; $date = $instance['date']; $date_format = $instance['date_format']; + $date_period_from = $instance['date_period_from']; + $date_period_to = $instance['date_period_to']; $disable_css = $instance['disable_css']; $disable_font_styles = $instance['disable_font_styles']; $hide_if_empty = $instance['hide_if_empty']; @@ -1726,6 +1824,12 @@ public function form( $instance ) { font-size:16px; line-height:20px; } + + ul.categories-select ul.children{ + margin-top: 6px; + margin-bottom: 12px; + margin-left: 24px; + } $m ) { - + if ( isset( $m['template'] ) && $m['template'] ) { ; } else { $m['template'] = convert_settings_to_template( $m ); } - + $m = wp_parse_args( $m, default_settings() ); if ( 0 === count( $meta ) ) { // new widget, use defaults. @@ -2838,7 +2942,7 @@ public function getCSSRules( $is_shortcode, &$rules ) { $styles['post_format_icon_status'] = ".cat-post-format-status:before { content: '\\e80a'; }"; $styles['post_format_icon_video'] = ".cat-post-format-video:before { content: '\\e801'; }"; $styles['post_format_icon_audio'] = ".cat-post-format-audio:before { content: '\\e803'; }"; - + } } @@ -2865,7 +2969,7 @@ public function getCSSRules( $is_shortcode, &$rules ) { $ret['p_styling'] = '#' . $widget_id . ' p {margin:5px 0 0 0}'; // since on bottom it will make the spacing on cover // bigger (add to the padding) use only top for now. $ret['div_styling'] = '#' . $widget_id . ' li > div {margin:5px 0 0 0; clear:both;}'; // Add margin between the rows. - + // use WP dashicons in the template (e.g. for premade Template 'All and icons') $ret['dashicons'] = '#' . $widget_id . ' .dashicons {vertical-align:middle;}'; } @@ -3060,3 +3164,36 @@ function wp_loaded() { register_meta( 'post', SHORTCODE_META, null, '__return_false' ); // do not allow access to the shortcode meta // use the pre 4.6 format for backward compatibility. } + + +/* Categories */ +// This is required to be sure Walker_Category_Checklist class is available +require_once ABSPATH . 'wp-admin/includes/template.php'; +/** + * Custom walker to print category checkboxes for widget forms + */ +class Walker_Category_Checklist_RadioButtons extends \Walker_Category_Checklist { + + private $name; + private $id; + + function __construct( $name = '', $id = '' ) { + $this->name = $name; + $this->id = $id; + } + + function start_el( &$output, $cat, $depth = 0, $args = array(), $id = 0 ) { + extract( $args ); + if ( empty( $taxonomy ) ) $taxonomy = 'category'; + $class = in_array( $cat->term_id, $popular_cats ) ? ' class="popular-category"' : ''; + $id = $this->id . '-' . $cat->term_id; + $checked = checked( in_array( $cat->term_id, $selected_cats ), true, false ); + $output .= "\n
  • " + . ''; + } +} \ No newline at end of file