defaults = array(
'title' => '',
'post_number' => 1,
'disable_image' => 0,
'image_alignment' => 'left',
'image_size' => '',
'disable_title' => 0,
'hide_category' => 0,
'hide_tags' => 0,
'hide_posted_on' => 1,
'hide_author' => 1,
'content_type' => 'excerpt',
'content_limit' => 200,
'more_text' => __( 'Read More ...', 'automobile' ),
);
$widget_ops = array(
'classname' => 'ct-featured-post ctfeaturedpostpage',
'description' => __( 'Displays featured posts with thumbnails', 'automobile' ),
);
$control_ops = array(
'id_base' => 'ct-featured-post',
);
parent::__construct(
'ct-featured-post', // Base ID
__( 'CT: Recent Posts', 'automobile' ), // Name
$widget_ops,
$control_ops
);
}
function form( $instance ) {
//* Merge with defaults
$instance = wp_parse_args( (array) $instance, $this->defaults );
$style = 'style="display: none;"';
?>
id="get_field_id( 'disable_image' ); ?>" name="get_field_name( 'disable_image' ); ?>" />
>
>
id="get_field_id( 'disable_title' ); ?>" name="get_field_name( 'disable_title' ); ?>" />
id="get_field_id( 'hide_category' ); ?>" name="get_field_name( 'hide_category' ); ?>" />
id="get_field_id( 'hide_tags' ); ?>" name="get_field_name( 'hide_tags' ); ?>" />
id="get_field_id( 'hide_posted_on' ); ?>" name="get_field_name( 'hide_posted_on' ); ?>" />
id="get_field_id( 'hide_author' ); ?>" name="get_field_name( 'hide_author' ); ?>" />
defaults );
$output .= $args['before_widget'];
// Set up the author bio
if ( ! empty( $instance['title'] ) ) {
$output .= $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title'];
}
$query_args = array(
'post_type' => 'post',
'posts_per_page' => $instance['post_number'],
'ignore_sticky_posts' => '1',
);
$wp_query = new WP_Query( $query_args );
if ( have_posts() ) :
$output .= '';
while ( have_posts() ) : the_post();
$output .= '
';
$title_attribute = the_title_attribute( array( 'echo' => false ) );
if( !$instance['disable_image'] && has_post_thumbnail() ) {
$output.= '
' .
get_the_post_thumbnail(
$post->ID,
$instance['image_size']
) .'
';
}
$output .= '';
$output .= '';
if ( 'excerpt' == $instance['content_type'] ) {
$output .= '
';
$output .= '
' . get_the_excerpt() . '
';
$output .= '
';
}
elseif ( 'content-limit' == $instance['content_type'] ) {
$output .= '
';
$output .= automobile_get_the_content_limit( (int) $instance['content_limit'], esc_html( $instance['more_text'] ) );
$output .= '
';
}
elseif( 'content' == $instance['content_type'] ) {
$output .= '
';
$output .= get_the_content( esc_html( $instance['more_text'] ) );
$output .= '
';
}
$output .= '
';
$output .= '';
endwhile;
$output .= '
';
endif;
//* Restore original query
wp_reset_query();
$output .= $args['after_widget'];
echo $output;
}
}
//From Codex: https://codex.wordpress.org/Widgets_API
add_action('widgets_init',
create_function('', 'return register_widget("automobile_featured_post_widget");')
);