__('A widget to display posts filtered by category.', 'bootredux') ) ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $categories = get_categories(); $cat = array(); $cat[-1] = __( 'Latest Posts', 'bootredux' ); foreach ($categories as $category) { $cat[$category->term_id] = $category->name; } /* Get Array of Image Sizes & Create Select Choices Array using function get_image_sizes() in extra.php */ $bootredux_widget_image_sizes = get_image_sizes(); $bootredux_widget_image_choices = array( 'none' => 'No Image', 'full' => 'Full Image'); foreach ($bootredux_widget_image_sizes as $bootredux_widget_image_name=>$bootredux_widget_image_array) { $bootredux_widget_image_choices[$bootredux_widget_image_name] = 'Image: '. $bootredux_widget_image_name . ' (' . $bootredux_widget_image_array['width'] . ' x ' . $bootredux_widget_image_array['height'] .'Px)'; } $fields = array( 'title' => array( 'bootredux_widgets_name' => 'title', 'bootredux_widgets_title' => __('Title', 'bootredux'), 'bootredux_widgets_field_type' => 'text', ), 'category' => array( 'bootredux_widgets_name' => 'category', 'bootredux_widgets_title' => __('Category', 'bootredux'), 'bootredux_widgets_field_type' => 'select', 'bootredux_widgets_field_options' => $cat ), 'image' => array( 'bootredux_widgets_name' => 'image', 'bootredux_widgets_title' => __('Thumbnail', 'bootredux'), 'bootredux_widgets_field_type' => 'select', 'bootredux_widgets_field_options' => $bootredux_widget_image_choices ), 'imagealign' => array( 'bootredux_widgets_name' => 'imagealign', 'bootredux_widgets_title' => __('Image Alignment', 'bootredux'), 'bootredux_widgets_field_type' => 'select', 'bootredux_widgets_field_options' => array('alignnone'=>'Align None','alignleft'=>'Align Left','alignright'=>'Align Right', 'aligncenter'=>'Align Center',) ), 'excerpt' => array( 'bootredux_widgets_name' => 'excerpt', 'bootredux_widgets_title' => __('Show excerpt?', 'bootredux'), 'bootredux_widgets_field_type' => 'checkbox', ), 'excerptcount' => array( 'bootredux_widgets_name' => 'excerptcount', 'bootredux_widgets_title' => __('Excerpt Word Count', 'bootredux'), 'bootredux_widgets_field_type' => 'number', 'bootredux_widgets_default' => 30, ), 'posts' => array( 'bootredux_widgets_name' => 'posts', 'bootredux_widgets_title' => __('No. of Posts to Show', 'bootredux'), 'bootredux_widgets_field_type' => 'number', 'bootredux_widgets_default' => 5, ), 'offset' => array( 'bootredux_widgets_name' => 'offset', 'bootredux_widgets_title' => __('No. of Posts to Ignore', 'bootredux'), 'bootredux_widgets_field_type' => 'number', 'bootredux_widgets_default' => 0, ), ); return $fields; } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { extract($args); $title = isset( $instance['title'] ) ? $instance['title'] : '' ; $category = isset( $instance['category'] ) ? $instance['category'] : '' ; $image = isset( $instance['image'] ) ? $instance['image'] : '' ; $imagealign = isset( $instance['imagealign'] ) ? $instance['imagealign'] : 'aligncenter' ; $showexcerpt = isset( $instance['excerpt'] ) ? $instance['excerpt'] : 0 ; $excerptcount = isset( $instance['excerptcount'] ) ? $instance['excerptcount'] : 30 ; $post_no = isset( $instance['posts'] ) ? $instance['posts'] : '' ; $post_offset = isset( $instance['offset'] ) ? $instance['offset'] : '' ; echo $before_widget; ?> $category, 'posts_per_page' => $post_no, 'offset' => $post_offset, 'ignore_sticky_posts' => 1 ); else: $args = array( 'posts_per_page' => $post_no, 'offset' => $post_offset, 'ignore_sticky_posts' => 1 ); endif; $query = new WP_Query($args); while($query->have_posts()): $query->the_post(); if ( ($image != '') && ($image != 'none') && has_post_thumbnail() ): $bootredux_catthumb = wp_get_attachment_image_src(get_post_thumbnail_id(), $image); $bootredux_catthumb_url = $bootredux_catthumb[0]; endif; ?>
widget_fields(); // Loop through fields foreach ($widget_fields as $widget_field) { extract($widget_field); // Use helper function to get updated field values $instance[$bootredux_widgets_name] = bootredux_widgets_updated_field_value($widget_field, $new_instance[$bootredux_widgets_name]); } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @uses bootredux_widgets_show_widget_field() defined in widget-fields.php */ public function form($instance) { $widget_fields = $this->widget_fields(); // Loop through fields foreach ($widget_fields as $widget_field) { // Make array elements available as variables extract($widget_field); $bootredux_widgets_field_value = !empty($instance[$bootredux_widgets_name]) ? esc_attr($instance[$bootredux_widgets_name]) : ''; bootredux_widgets_show_widget_field($this, $widget_field, $bootredux_widgets_field_value); } } } /* * Add Section Content Widget Block * Based on Bootredux WP theme */ class Bootredux_Display_Block extends WP_Widget { public function __construct() { parent::__construct( 'bootredux_display_block', 'Content Block', array( 'description' => __('Display stylized content blocks.', 'bootredux') ) ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $categories = get_categories(); $cat = array(); $cat[-1] = __( 'Latest Posts', 'bootredux' ); foreach ($categories as $category) { $cat[$category->term_id] = $category->name; } $bootredux_image_path_url = get_template_directory_uri().'/images/'; $fields = array( 'title' => array( 'bootredux_widgets_name' => 'title', 'bootredux_widgets_title' => __('Title', 'bootredux'), 'bootredux_widgets_field_type' => 'text', 'bootredux_widgets_default' => '', ), 'category' => array( 'bootredux_widgets_name' => 'category', 'bootredux_widgets_title' => __('Category', 'bootredux'), 'bootredux_widgets_field_type' => 'category', 'bootredux_widgets_default' => '', ), 'textalign' => array( 'bootredux_widgets_name' => 'textalign', 'bootredux_widgets_title' => __('Text Alignment', 'bootredux'), 'bootredux_widgets_field_type' => 'select', 'bootredux_widgets_field_options' => array( 'left'=>'Left', 'right'=>'Right', 'center'=>'Center', 'justify'=>'Justify'), 'bootredux_widgets_default' => 'alignleft', ), 'showdate' => array( 'bootredux_widgets_name' => 'showdate', 'bootredux_widgets_title' => __('Display published date?', 'bootredux'), 'bootredux_widgets_field_type' => 'checkbox', 'bootredux_widgets_default' => 0, ), 'showauthor' => array( 'bootredux_widgets_name' => 'showauthor', 'bootredux_widgets_title' => __('Display author name?', 'bootredux'), 'bootredux_widgets_field_type' => 'checkbox', 'bootredux_widgets_default' => 0, ), 'featuredimage' => array( 'bootredux_widgets_name' => 'featuredimage', 'bootredux_widgets_title' => __('Require featured images?', 'bootredux'), 'bootredux_widgets_field_type' => 'checkbox', 'bootredux_widgets_default' => 0, ), 'excerpt' => array( 'bootredux_widgets_name' => 'excerpt', 'bootredux_widgets_title' => __('Show post excerpt?', 'bootredux'), 'bootredux_widgets_field_type' => 'checkbox', 'bootredux_widgets_default' => 0, ), 'excerptcount' => array( 'bootredux_widgets_name' => 'excerptcount', 'bootredux_widgets_title' => __('No. of words in excerpt', 'bootredux'), 'bootredux_widgets_field_type' => 'number', 'bootredux_widgets_default' => '', ), 'offset' => array( 'bootredux_widgets_name' => 'offset', 'bootredux_widgets_title' => __('No.of posts to ignore', 'bootredux'), 'bootredux_widgets_field_type' => 'number', 'bootredux_widgets_default' => 0, ), 'layout' => array( 'bootredux_widgets_name' => 'layout', 'bootredux_widgets_title' => __('Display Style', 'bootredux'), 'bootredux_widgets_field_type' => 'selector', 'bootredux_widgets_field_options' => array( 'layout1' => $bootredux_image_path_url.'layout1.png', 'layout5' => $bootredux_image_path_url.'layout5.png', 'layout3' => $bootredux_image_path_url.'layout3.png', 'layout2' => $bootredux_image_path_url.'layout2.png', 'layout4' => $bootredux_image_path_url.'layout4.png', 'layout6' => $bootredux_image_path_url.'layout6.png', 'layout7' => $bootredux_image_path_url.'layout7.png', 'layout8' => $bootredux_image_path_url.'layout8.png', 'layout9' => $bootredux_image_path_url.'layout9.png', ), 'bootredux_widgets_default' => 'layout1', ), 'background' => array( 'bootredux_widgets_name' => 'background', 'bootredux_widgets_title' => __('Background Color (Pro)', 'bootredux'), 'bootredux_widgets_field_type' => 'select', 'bootredux_widgets_field_options' => array( 'default' => 'Default', 'none' => 'None', ), 'bootredux_widgets_default' => 'default', ), 'morelink' => array( 'bootredux_widgets_name' => 'morelink', 'bootredux_widgets_title' => __('Display category/archive link?', 'bootredux'), 'bootredux_widgets_field_type' => 'checkbox', 'bootredux_widgets_default' => 0, ), 'moretext' => array( 'bootredux_widgets_name' => 'moretext', 'bootredux_widgets_title' => __('Text for category/archive link', 'bootredux'), 'bootredux_widgets_field_type' => 'text', 'bootredux_widgets_default' => '', ), 'morestyle' => array( 'bootredux_widgets_name' => 'morestyle', 'bootredux_widgets_title' => __('Category link button style', 'bootredux'), 'bootredux_widgets_field_type' => 'select', 'bootredux_widgets_field_options' => array( 'light' => 'Light', 'primary' => 'Primary', 'success' => 'Success', 'info' => 'Info', 'warning' => 'Warning', 'danger' => 'Danger', 'dark' => 'Dark', 'outline-light' => 'Outline Light', 'outline-primary' => 'Outline Primary', 'outline-success' => 'Outline Success', 'outline-info' => 'Outline Info', 'outline-warning' => 'Outline Warning', 'outline-danger' => 'Outline Danger', 'outline-dark' => 'Outline Dark', ), 'bootredux_widgets_default' => 'light', ), ); return $fields; } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { extract($args); $blockargs = array(); $title = $blockargs['title'] = isset( $instance['title'] ) ? $instance['title'] : '' ; $blockargs['category'] = isset( $instance['category'] ) ? $instance['category'] : '-1' ; $blockargs['textalign'] = isset( $instance['textalign'] ) ? $instance['textalign'] : 'left' ; $blockargs['showdate'] = isset( $instance['showdate'] ) ? $instance['showdate'] : 0 ; $blockargs['showauthor'] = isset( $instance['showauthor'] ) ? $instance['showauthor'] : 0 ; $blockargs['excerpt'] = isset( $instance['excerpt'] ) ? $instance['excerpt'] : 0 ; $blockargs['excerptcount'] = isset( $instance['excerptcount'] ) ? $instance['excerptcount'] : 50 ; $blockargs['featuredimage'] = isset( $instance['featuredimage'] ) ? $instance['featuredimage'] : '0' ; $blockargs['offset'] = isset( $instance['offset'] ) ? $instance['offset'] : 0 ; $blockargs['layout'] = isset( $instance['layout'] ) ? $instance['layout'] : 'layout1' ; $blockargs['background'] = isset( $instance['background'] ) ? $instance['background'] : 'default' ; $blockargs['morelink'] = isset( $instance['morelink'] ) ? $instance['morelink'] : 0 ; $blockargs['moretext'] = isset( $instance['moretext'] ) ? $instance['moretext'] : '' ; $blockargs['morestyle'] = isset( $instance['morestyle'] ) ? $instance['morestyle'] : 'light' ; if ( isset($blockargs['background']) && ($blockargs['background'] != 'default') ) { if ( ($blockargs['background'] == 'primary') || ($blockargs['background'] == 'info') || ($blockargs['background'] == 'dark') || ($blockargs['background'] == 'success') || ($blockargs['background'] == 'danger') || ($blockargs['background'] == 'warning') ) { $backgroundclass = ' bg-'. $blockargs['background'] . ' text-white'; } else { $backgroundclass = ' bg-'. $blockargs['background']; } } else { $backgroundclass = ' bg-default'; } echo $before_widget . '' . $after_widget; } /** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @param array $new_instance Values just sent to be saved. * @param array $old_instance Previously saved values from database. * * @uses bootredux_widgets_updated_field_value() defined in widget-fields.php * * @return array Updated safe values to be saved. */ public function update($new_instance, $old_instance) { $instance = $old_instance; $widget_fields = $this->widget_fields(); // Loop through fields foreach ($widget_fields as $widget_field) { extract($widget_field); // Use helper function to get updated field values $instance[$bootredux_widgets_name] = bootredux_widgets_updated_field_value($widget_field, $new_instance[$bootredux_widgets_name]); } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @uses bootredux_widgets_show_widget_field() defined in widget-fields.php */ public function form($instance) { $widget_fields = $this->widget_fields(); // Loop through fields foreach ($widget_fields as $widget_field) { // Make array elements available as variables extract($widget_field); $bootredux_widgets_field_value = !empty($instance[$bootredux_widgets_name]) ? esc_attr($instance[$bootredux_widgets_name]) : ''; bootredux_widgets_show_widget_field($this, $widget_field, $bootredux_widgets_field_value); } } } /* * Add Related Posts Widget * Based on Bootredux WP theme */ class Bootredux_Related_Posts extends WP_Widget { public function __construct() { parent::__construct( 'bootredux_related_posts', 'Related Posts', array( 'description' => __('Display related posts on single post pages.', 'bootredux') ) ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $bootredux_image_path_url = get_template_directory_uri().'/images/'; $fields = array( 'title' => array( 'bootredux_widgets_name' => 'title', 'bootredux_widgets_title' => __('Title', 'bootredux'), 'bootredux_widgets_field_type' => 'text', 'bootredux_widgets_default' => '', ), 'relation' => array( 'bootredux_widgets_name' => 'relation', 'bootredux_widgets_title' => __('Relation Type', 'bootredux'), 'bootredux_widgets_field_type' => 'select', 'bootredux_widgets_field_options' => array( 'category' => 'Categories', 'tag' => 'Tags', 'both' => 'Categories & Tags', ), 'bootredux_widgets_default' => 'category', ), 'textalign' => array( 'bootredux_widgets_name' => 'textalign', 'bootredux_widgets_title' => __('Text Alignment', 'bootredux'), 'bootredux_widgets_field_type' => 'select', 'bootredux_widgets_field_options' => array( 'left'=>'Left', 'right'=>'Right', 'center'=>'Center', 'justify'=>'Justify'), 'bootredux_widgets_default' => 'alignleft', ), 'showdate' => array( 'bootredux_widgets_name' => 'showdate', 'bootredux_widgets_title' => __('Display published date?', 'bootredux'), 'bootredux_widgets_field_type' => 'checkbox', 'bootredux_widgets_default' => 0, ), 'showauthor' => array( 'bootredux_widgets_name' => 'showauthor', 'bootredux_widgets_title' => __('Display author name?', 'bootredux'), 'bootredux_widgets_field_type' => 'checkbox', 'bootredux_widgets_default' => 0, ), 'featuredimage' => array( 'bootredux_widgets_name' => 'featuredimage', 'bootredux_widgets_title' => __('Require featured images?', 'bootredux'), 'bootredux_widgets_field_type' => 'checkbox', 'bootredux_widgets_default' => 0, ), 'excerpt' => array( 'bootredux_widgets_name' => 'excerpt', 'bootredux_widgets_title' => __('Show post excerpt?', 'bootredux'), 'bootredux_widgets_field_type' => 'checkbox', 'bootredux_widgets_default' => 0, ), 'excerptcount' => array( 'bootredux_widgets_name' => 'excerptcount', 'bootredux_widgets_title' => __('No. of words in excerpt', 'bootredux'), 'bootredux_widgets_field_type' => 'number', 'bootredux_widgets_default' => '', ), 'layout' => array( 'bootredux_widgets_name' => 'layout', 'bootredux_widgets_title' => __('Display Style', 'bootredux'), 'bootredux_widgets_field_type' => 'selector', 'bootredux_widgets_field_options' => array( 'layout1' => $bootredux_image_path_url.'layout1.png', 'layout5' => $bootredux_image_path_url.'layout5.png', 'layout3' => $bootredux_image_path_url.'layout3.png', 'layout2' => $bootredux_image_path_url.'layout2.png', 'layout4' => $bootredux_image_path_url.'layout4.png', 'layout6' => $bootredux_image_path_url.'layout6.png', 'layout7' => $bootredux_image_path_url.'layout7.png', 'layout8' => $bootredux_image_path_url.'layout8.png', 'layout9' => $bootredux_image_path_url.'layout9.png', ), 'bootredux_widgets_default' => 'layout1', ), 'background' => array( 'bootredux_widgets_name' => 'background', 'bootredux_widgets_title' => __('Background Color (Pro)', 'bootredux'), 'bootredux_widgets_field_type' => 'select', 'bootredux_widgets_field_options' => array( 'default' => 'Default', 'none' => 'None', ), 'bootredux_widgets_default' => 'default', ), ); return $fields; } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { extract($args); $blockargs = array(); $title = $blockargs['title'] = isset( $instance['title'] ) ? $instance['title'] : '' ; $blockargs['relation'] = isset( $instance['relation'] ) ? $instance['relation'] : 'category' ; $blockargs['textalign'] = isset( $instance['textalign'] ) ? $instance['textalign'] : 'left' ; $blockargs['showdate'] = isset( $instance['showdate'] ) ? $instance['showdate'] : 0 ; $blockargs['showauthor'] = isset( $instance['showauthor'] ) ? $instance['showauthor'] : 0 ; $blockargs['excerpt'] = isset( $instance['excerpt'] ) ? $instance['excerpt'] : 0 ; $blockargs['excerptcount'] = isset( $instance['excerptcount'] ) ? $instance['excerptcount'] : 50 ; $blockargs['featuredimage'] = isset( $instance['featuredimage'] ) ? $instance['featuredimage'] : '0' ; $blockargs['layout'] = isset( $instance['layout'] ) ? $instance['layout'] : 'layout1' ; $blockargs['background'] = isset( $instance['background'] ) ? $instance['background'] : 'default' ; $blockargs['morelink'] = isset( $instance['morelink'] ) ? $instance['morelink'] : 0 ; $blockargs['moretext'] = isset( $instance['moretext'] ) ? $instance['moretext'] : '' ; $blockargs['morestyle'] = isset( $instance['morestyle'] ) ? $instance['morestyle'] : 'light' ; if ( isset($blockargs['background']) && ($blockargs['background'] != 'default') ) { if ( ($blockargs['background'] == 'primary') || ($blockargs['background'] == 'info') || ($blockargs['background'] == 'dark') || ($blockargs['background'] == 'success') || ($blockargs['background'] == 'danger') || ($blockargs['background'] == 'warning') ) { $backgroundclass = ' bg-'. $blockargs['background'] . ' text-white'; } else { $backgroundclass = ' bg-'. $blockargs['background']; } } else { $backgroundclass = ' bg-default'; } echo $before_widget . '' . $after_widget; } /** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @param array $new_instance Values just sent to be saved. * @param array $old_instance Previously saved values from database. * * @uses bootredux_widgets_updated_field_value() defined in widget-fields.php * * @return array Updated safe values to be saved. */ public function update($new_instance, $old_instance) { $instance = $old_instance; $widget_fields = $this->widget_fields(); // Loop through fields foreach ($widget_fields as $widget_field) { extract($widget_field); // Use helper function to get updated field values $instance[$bootredux_widgets_name] = bootredux_widgets_updated_field_value($widget_field, $new_instance[$bootredux_widgets_name]); } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @uses bootredux_widgets_show_widget_field() defined in widget-fields.php */ public function form($instance) { $widget_fields = $this->widget_fields(); // Loop through fields foreach ($widget_fields as $widget_field) { // Make array elements available as variables extract($widget_field); $bootredux_widgets_field_value = !empty($instance[$bootredux_widgets_name]) ? esc_attr($instance[$bootredux_widgets_name]) : ''; bootredux_widgets_show_widget_field($this, $widget_field, $bootredux_widgets_field_value); } } } /* * Add Ad Widget * Based on Bootredux WP theme */ class Bootredux_Blank_Widget extends WP_Widget { public function __construct() { parent::__construct( 'bootredux_blank_widget', 'Raw Ad / HTML Block', array( 'description' => __('A widget to display raw HTML or ad code without styling.', 'bootredux') ) ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $fields = array( 'title' => array( 'bootredux_widgets_name' => 'title', 'bootredux_widgets_title' => __('Title', 'bootredux'), 'bootredux_widgets_field_type' => 'text', 'bootredux_widgets_default' => '', ), 'htmlcode' => array( 'bootredux_widgets_name' => 'htmlcode', 'bootredux_widgets_title' => __('HTML / Ad Code', 'bootredux'), 'bootredux_widgets_field_type' => 'textarea', 'bootredux_widgets_row' => '8', 'bootredux_widgets_default' => '', ), ); return $fields; } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { extract($args); $title = isset( $instance['title'] ) ? $instance['title'] : '' ; $content = isset( $instance['htmlcode'] ) ? $instance['htmlcode'] : '' ; if (!empty($title)): esc_html($title); endif; if ( !empty($content) ): echo '