'business-center-profeatured-content-widget', 'description' => esc_html__( 'A widget to display featured content.', 'business-center-pro' ), ); parent::__construct( 'business-center-profeatured-content-widget', esc_html__( 'TP : Featured Content', 'business-center-pro' ), $widget_ops ); } /** * Outputs the content of the widget * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { // outputs the content of the widget if ( ! isset( $args['widget_id'] ) ) { $args['widget_id'] = $this->id; } // Get title value $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : esc_html__( 'Featured Content', 'business-center-pro' ); // Get post type value $post_type = isset( $instance['post_type'] ) ? esc_html( $instance['post_type'] ) : 'post'; // Get post id value $post_id = isset( $instance['post_id'] ) ? absint( $instance['post_id'] ) : ''; // Get page id value $page_id = isset( $instance['page_id'] ) ? absint( $instance['page_id'] ) : ''; // Get content type featured_image_size $content_type = isset( $instance['content_type'] ) ? esc_html( $instance['content_type'] ) : ''; // Get featured image size $featured_image_size = isset( $instance['featured_image_size'] ) ? esc_html( $instance['featured_image_size'] ) : ''; // Get hide image value $hide_title = isset( $instance['hide_title'] ) ? (bool) $instance['hide_title'] : false; echo $args['before_widget']; if ( ! empty( $title ) ) { echo $args['before_title'] . esc_html( $title ) . $args['after_title']; } if ( 'post' == $post_type ) { $query_args = array( 'p' => $post_id ); } elseif ( 'page' == $post_type ) { $query_args = array( 'page_id' => $page_id ); } $query = new WP_Query( $query_args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); if ( ! $hide_title ) { ?>
', esc_url( get_permalink() ) ), '' ); ?>
$_wp_additional_image_sizes[ $_size ]['width'], 'height' => $_wp_additional_image_sizes[ $_size ]['height'], ); } } foreach( $sizes as $size => $atts ){ $size_title = ucwords( str_replace("-"," ", $size ) ); $img_sizes[ $size ] = $size_title . ' (' . implode( 'x', $atts ) . ')'; } return $img_sizes; } /** * Outputs the options form on admin * * @param array $instance The widget options */ public function form( $instance ) { $title = isset( $instance['title'] ) ? esc_html( $instance['title'] ) : esc_html__( 'Featured Content', 'business-center-pro' ); $post_type = isset( $instance['post_type'] ) ? esc_html( $instance['post_type'] ) : 'post'; $post_id = isset( $instance['post_id'] ) ? absint( $instance['post_id'] ) : ''; $content_type = isset( $instance['content_type'] ) ? esc_html( $instance['content_type'] ) : 'excerpt'; $featured_image_size = isset( $instance['featured_image_size'] ) ? esc_html( $instance['featured_image_size'] ) : 'thumbnail'; $hide_title = isset( $instance['hide_title'] ) ? (bool) $instance['hide_title'] : false; $page_id = isset( $instance['page_id'] ) ? (int) $instance['page_id'] : 0; ?>


'ids', // Only get post IDs 'posts_per_page'=> -1, ) ); if ( ! in_array( $post_id, $post_ids ) ) : ?>

esc_attr( $this->get_field_name( 'page_id' ) ), 'selected' => $page_id ) );?>

/>