function widget($args, $instance) { global $sc_recipes_post_type, $sc_theme_globals; $card_layout_classes = array('full-width', 'one-half', 'one-third', 'one-fourth', 'one-fifth'); extract($args); /* Our variables from the widget settings. */ $title = apply_filters('widget_title', isset($instance['title']) ? $instance['title'] : __('Display latest recipes', 'socialchef')); $number_of_recipes = isset($instance['number_of_recipes']) ? (int) $instance['number_of_recipes'] : 5; $sort_by = isset($instance['sort_by']) ? (int) $instance['sort_by'] : 'title'; $sort_descending = isset($instance['sort_by']) && $instance['sort_descending'] == '1'; $order = $sort_descending ? 'DESC' : 'ASC'; $recipe_category_ids = isset($instance['recipe_category_ids']) ? (array) $instance['recipe_category_ids'] : array(); $recipe_difficulty_ids = isset($instance['recipe_difficulty_ids']) ? (array) $instance['recipe_difficulty_ids'] : array(); $recipe_meal_course_ids = isset($instance['recipe_meal_course_ids']) ? (array) $instance['recipe_meal_course_ids'] : array(); $recipes_per_row = isset($instance['recipes_per_row']) ? (int) $instance['recipes_per_row'] : 3; $show_featured_only = isset($instance['show_featured_only']) && $instance['show_featured_only'] == '1'; $display_mode = isset($instance['display_mode']) ? $instance['display_mode'] : 'small'; echo $before_widget; /* Display Widget */ $recipe_results = $sc_recipes_post_type->list_recipes(1, $number_of_recipes, $sort_by, $order, $recipe_meal_course_ids, $recipe_difficulty_ids, array(), array(), array(), $show_featured_only); ?> <!--cwrap--> <div class="cwrap"> <?php if ($display_mode == 'card') { ?> <header class="s-title"> <?php echo $before_title . $title . $after_title; ?> </header> <?php } else { echo $before_title . $title . $after_title; } if ($display_mode == 'small') { if (count($recipe_results) > 0 && $recipe_results['total'] > 0) { ?> <ul class="articles_latest recipes_latest"> <?php $recipes = $recipe_results['results']; for ($i = 0; $i < count($recipes); $i++) { if (isset($recipes[$i])) { $recipe = $recipes[$i]; $recipe_permalink = get_permalink($recipe->ID); $recipe_title = get_the_title($recipe->ID); $image_id = get_post_thumbnail_id($recipe->ID); $image_src = ''; if ($image_id > 0) { $image_src = SocialChef_Theme_Utils::get_image_src($image_id, 'thumbnail'); } ?> <li> <a href="<?php echo esc_url($recipe_permalink); ?> "> <?php if (!empty($image_src)) { ?> <img src="<?php echo esc_url($image_src); ?> " alt="<?php echo esc_attr($recipe_title); ?> " /> <?php } ?> <h6><?php echo $recipe_title; ?> </h6> </a> </li> <?php } } ?> </ul> <?php } } else { if (count($recipe_results) > 0 && $recipe_results['total'] > 0) { ?> <!--entries--> <div class="entries row"><?php $recipes = $recipe_results['results']; for ($i = 0; $i < count($recipes); $i++) { if (isset($recipes[$i])) { $recipe = $recipes[$i]; global $post, $sc_recipe_class; $post = $recipe; setup_postdata($post); $sc_recipe_class = $card_layout_classes[$recipes_per_row - 1]; get_template_part('includes/parts/recipe', 'item'); } } ?> <!--//entries--> <div class="quicklinks"> <a href="/consulter-nos-offres" class="button"><?php _e('Toutes nos offres', 'socialchef'); ?> </a> <a href="javascript:void(0)" class="button scroll-to-top"><?php _e('Haut', 'socialchef'); ?> </a> </div> </div><?php } } ?> </div> <!--//cwrap--> <?php /* After widget (defined by themes). */ echo $after_widget; }
function widget($args, $instance) { global $sc_theme_globals; $card_layout_classes = array('full-width', 'one-half', 'one-third', 'one-fourth', 'one-fifth'); extract($args); /* Our variables from the widget settings. */ $title = apply_filters('widget_title', isset($instance['title']) ? $instance['title'] : __('Display latest posts', 'socialchef')); $number_of_posts = isset($instance['number_of_posts']) ? (int) $instance['number_of_posts'] : 5; $sort_by = isset($instance['sort_by']) ? (int) $instance['sort_by'] : 'title'; $sort_descending = isset($instance['sort_by']) && $instance['sort_descending'] == '1'; $order = $sort_descending ? 'DESC' : 'ASC'; $post_category_ids = isset($instance['post_category_ids']) ? (array) $instance['post_category_ids'] : array(); $posts_per_row = isset($instance['posts_per_row']) ? (int) $instance['posts_per_row'] : 3; $show_featured_only = isset($instance['show_featured_only']) && $instance['show_featured_only'] == '1'; $display_mode = isset($instance['display_mode']) ? $instance['display_mode'] : 'small'; echo $before_widget; ?> <!--cwrap--> <div class="cwrap"> <?php /* Display Widget */ $post_args = array('post_type' => 'post', 'post_status' => array('publish'), 'posts_per_page' => $number_of_posts, 'paged' => 1, 'orderby' => $sort_by, 'suppress_filters' => false, 'order' => $order, 'meta_query' => array('relation' => 'AND')); if (count($post_category_ids) > 0) { $numeric_category_ids = array(); foreach ($post_category_ids as $post_category_id) { $numeric_category_ids[] = (int) $post_category_id; } $post_category_ids_str = implode(',', $numeric_category_ids); $post_args['category'] = $post_category_ids_str; } if ($display_mode == 'card') { ?> <header class="s-title"> <?php echo $before_title . $title . $after_title; ?> </header> <?php } else { echo $before_title . $title . $after_title; } $posts_array = get_posts($post_args); if ($display_mode == 'small') { if (count($posts_array) > 0) { ?> <ul class="articles_latest"> <?php for ($i = 0; $i < count($posts_array); $i++) { if (isset($posts_array[$i])) { $article = $posts_array[$i]; $article_permalink = get_permalink($article->ID); $article_title = get_the_title($article->ID); $image_id = get_post_thumbnail_id($article->ID); $image_src = ''; if ($image_id > 0) { $image_src = SocialChef_Theme_Utils::get_image_src($image_id, 'thumbnail'); } ?> <li> <a href="<?php echo esc_url($article_permalink); ?> "> <?php if (!empty($image_src)) { ?> <img src="<?php echo esc_url($image_src); ?> " alt="<?php echo esc_attr($article_title); ?> " /> <?php } ?> <h6><?php echo $article_title; ?> </h6> </a> </li> <?php } } ?> </ul> <?php } } else { if (count($posts_array)) { ?> <!--entries--> <div class="entries row"><?php for ($i = 0; $i < count($posts_array); $i++) { $post_result = $posts_array[$i]; global $post, $sc_post_class; $post = $post_result; setup_postdata($post); $sc_post_class = $card_layout_classes[$posts_per_row - 1]; get_template_part('includes/parts/post', 'item'); } ?> <!--//entries--> <div class="quicklinks"> <a href="<?php echo esc_url($sc_theme_globals->get_blog_posts_root_url()); ?> " class="button"><?php _e('More posts', 'socialchef'); ?> </a> <a href="javascript:void(0)" class="button scroll-to-top"><?php _e('Back to top', 'socialchef'); ?> </a> </div> </div><?php } } ?> </div> <!--//cwrap--> <?php /* After widget (defined by themes). */ echo $after_widget; }