__( 'Display Post Slider.', 'best-shop' ), )
);
}
public function widget( $args, $instance ) {
$max_items = ( ! empty( $instance['max_items'] ) ) ? absint( $instance['max_items'] ) : 3;
$category = ( ! empty( $instance['category'] ) ) ? wp_strip_all_tags( $instance['category'] ) : -1;
$hide_title_price = ( ! empty( $instance['hide_title_price'] ) ) ? true : false;
$navigation = ( ! empty( $instance['navigation'] ) ) ? true : false;
$max_height = (!empty($instance['max_height'])) ? absint($instance['max_height']) : 400;
$speed = (!empty($instance['speed'])) ? absint($instance['speed']) : 4;
$button_lbl = ( ! empty( $instance['button_lbl'] ) ) ? wp_strip_all_tags( $instance['button_lbl'] ) : '';
$args = array();
if( $category == -1 ){
$args = array ( 'post_type' => 'post', 'posts_per_page'=> $max_items );
} else {
$args = array ( 'post_type' => 'post', 'posts_per_page'=> $max_items, 'cat' => $category );
}
$loop = new WP_Query($args );
$i = 1;
$items = array();
while( $loop->have_posts() ) : $loop->the_post();
$thumb_id = get_post_thumbnail_id(get_the_ID());
$url = get_the_post_thumbnail_url(get_the_ID(), 'full');
if(!$url) {
$url = get_template_directory_uri().'/images/empty.png';
}
$alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);
$link = get_permalink();
$title = get_the_title();
$content = get_the_excerpt();
$item = array ( 'link' => $link ,
'image_url' => $url ,
'content' => $content ,
'title' => $title,
'alt' => $alt
);
array_push($items, $item);
$i++;
endwhile;
wp_reset_postdata();
global $best_shop_uniqueue_id ;
$best_shop_uniqueue_id += 1;
$carousal_id = 'product-carousal-'.$best_shop_uniqueue_id;
//carousal begin
echo '
';
echo '
';
$active = 'active';
$item_count = count($items);
foreach ($items as $slides){
echo '
';
?>
';
}
//indicators, navigation
if($item_count>1 ) {
if($navigation == true) {
?>
';
$s = 0;
foreach ($items as $slides) {
echo '
';
$active = '';
$s++;
}
echo '';
}//indicators, navigation
echo '
';
echo '
';
}
public function form( $instance ) {
$max_items = ( ! empty( $instance['max_items'] ) ) ? absint( $instance['max_items'] ) : 3;
$category = ( ! empty( $instance['category'] ) ) ? wp_strip_all_tags( $instance['category'] ) : -1;
$hide_title_price = ( ! empty( $instance['hide_title_price'] )) ? (bool) $instance['hide_title_price'] : false;
$navigation = ( ! empty( $instance['navigation'] )) ? (bool) $instance['navigation'] : false;
$max_height = (!empty($instance['max_height'])) ? absint($instance['max_height']) : 400;
$speed = (!empty($instance['animation'])) ? absint($instance['speed']) : 4;
$button_lbl = ( ! empty( $instance['button_lbl'] ) ) ? wp_strip_all_tags( $instance['button_lbl'] ) : esc_html__('VIEW MORE', 'best-shop');
$args = get_categories( array(
'orderby' => 'name',
'parent' => 0
));
$categories = get_categories( $args );
$category_list = '';
if(0 == $category){
$category_list = $category_list.'
';
} else{
$category_list = $category_list.'
';
}
foreach ( $categories as $cat ) {
$selected ='';
if(($cat->term_id)==$category){
$selected ='Selected=selected';
}
$category_list = $category_list.'
';
}
?>
id="get_field_id( 'hide_title_price' )); ?>" name="get_field_name( 'hide_title_price' )); ?>" />
id="get_field_id( 'navigation' )); ?>" name="get_field_name( 'navigation' )); ?>" />