* @copyright Copyright (c) 2018, Chris Baldelomar * @link https://webplantmedia.com/product/brimstone-wordpress-theme/ * @license http://www.gnu.org/licenses/gpl-2.0.html */ if ( ! class_exists( 'Brimstone_Content_Widget_Blog_Post' ) ) : /** * Class: Display static content from an specific page. * * @since Brimstone 1.01 * * @see Brimstone_Widget */ class Brimstone_Content_Widget_Blog_Post extends Brimstone_Widget { /** * __construct * * @since Brimstone 1.01 * * @return void */ public function __construct() { $this->widget_id = 'brimstone-content-widget-blog-posts'; $this->widget_description = esc_html__( 'Displays content from blog posts on your widgetized page.', 'brimstone' ); $this->widget_name = esc_html__( 'Brimstone: Blog Posts', 'brimstone' ); $this->settings = array( 'title' => array( 'type' => 'text', 'std' => esc_html__( 'BLOG', 'brimstone' ), 'label' => esc_html__( 'Title:', 'brimstone' ), 'sanitize' => 'text', ), 'post_ids' => array( 'type' => 'post', 'std' => '', 'label' => esc_html__( 'Post ID\'s:', 'brimstone' ), 'sanitize' => 'post_ids', ), 'category' => array( 'type' => 'category', 'std' => 0, 'label' => esc_html__( 'Category:', 'brimstone' ), 'sanitize' => 'number', ), 'post_count' => array( 'type' => 'number', 'std' => 6, 'step' => 1, 'min' => 1, 'max' => 100, 'label' => esc_html__( 'Number of Posts:', 'brimstone' ), 'sanitize' => 'number', ), 'columns' => array( 'type' => 'select', 'std' => 3, 'label' => esc_html__( 'Columns:', 'brimstone' ), 'options' => array( 2 => esc_html__( '2 Columns', 'brimstone' ), 3 => esc_html__( '3 Columns', 'brimstone' ), ), 'sanitize' => 'number', ), 'random_order' => array( 'type' => 'checkbox', 'std' => 0, 'label' => esc_html__( 'Random order?', 'brimstone' ), 'sanitize' => 'checkbox', ), 'button_text' => array( 'type' => 'text', 'std' => esc_html__( 'See All Posts', 'brimstone' ), 'label' => esc_html__( 'Button Text:', 'brimstone' ), 'sanitize' => 'text', ), 'button_link' => array( 'type' => 'text', 'std' => '', 'label' => esc_html__( 'Button Link:', 'brimstone' ), 'sanitize' => 'url', ), 'button_style' => array( 'type' => 'select', 'std' => 'button-2', 'label' => esc_html__( 'Button Style:', 'brimstone' ), 'options' => array( 'default' => esc_html__( 'Default Button', 'brimstone' ), 'button-1' => esc_html__( 'Image Button 1', 'brimstone' ), 'button-2' => esc_html__( 'Image Button 2', 'brimstone' ), ), 'sanitize' => 'text', ), 'margin_bottom' => array( 'type' => 'number', 'std' => 80, 'step' => 1, 'min' => 0, 'max' => 300, 'label' => esc_html__( 'Bottom margin of widget:', 'brimstone' ), 'sanitize' => 'number', ), ); parent::__construct(); } /** * Widget function. * * @since Brimstone 1.01 * * @param array $args * @param array $instance * @return void */ public function widget( $args, $instance ) { $o = $this->sanitize( $instance ); $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; $post_args = array( 'posts_per_page' => $o['post_count'], 'ignore_sticky_posts' => 1, 'paged' => $paged, ); if ( ! empty( $o['category'] ) ) { $post_args['category__in'] = $o['category']; } if ( ! empty( $o['post_ids'] ) ) { $post_args['post__in'] = explode( ',', $o['post_ids'] ); $post_args['orderby'] = 'post__in'; } if ( 1 === $o['random_order'] ) { $post_args['orderby'] = 'rand'; } /* add_filter( 'excerpt_length', array( $this, 'custom_excerpt_length' ), 999 ); */ $post = new WP_Query( $post_args ); $style = array(); if ( ! empty( $o['margin_bottom'] ) ) { $style[] = 'margin-bottom:' . $o['margin_bottom'] . 'px;'; } echo $args['before_widget']; /* WPCS: XSS OK. HTML output. */ // Allow site-wide customization of the 'Read more' link text. $read_more = apply_filters( 'brimstone_read_more_text', esc_html__( 'Read more', 'brimstone' ) ); ?>