'sydney_portfolio_widget', 'description' => __( 'Display your projects in a grid.', 'sydney') ); parent::__construct(false, $name = __('Sydney FP: Portfolio', 'sydney'), $widget_ops); $this->alt_option_name = 'sydney_portfolio_widget'; } public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); $number = ( ! empty( $instance['number'] ) ) ? intval( $instance['number'] ) : -1; $includes = isset($instance['includes']) ? $instance['includes'] : ''; $show_filter = isset( $instance['show_filter'] ) ? $instance['show_filter'] : false; $show_project_title = isset( $instance['show_project_title'] ) ? $instance['show_project_title'] : false; $show_all_text = isset( $instance['show_all_text'] ) ? $instance['show_all_text'] : ''; echo $args['before_widget']; if ( ! empty( $title ) ) { echo $args['before_title'] . $title . $args['after_title']; } $options = array( 'posts' => $number, 'post_type' => 'projects', 'include' => $includes, 'filter' => $show_filter, 'show_all_text' => ! empty( $show_all_text ) ? $show_all_text : __('Show all', 'sydney') ); $output = ''; //Start output $output .= '
'; if ($options['include'] && $options['filter'] == 1) { $included_terms = explode( ',', $options['include'] ); $included_ids = array(); foreach( $included_terms as $term ) { $term_obj = get_term_by( 'slug', $term, 'category'); if (is_object($term_obj)) { $term_id = $term_obj->term_id; $included_ids[] = $term_id; } } $id_string = implode( ',', $included_ids ); $terms = get_terms( 'category', array( 'include' => $id_string ) ); //Build the filter $output .= ''; } //Build the layout $output .= '
'; $output .= '
'; $the_query = new WP_Query( array ( 'post_type' => $options['post_type'], 'posts_per_page' => $options['posts'], 'category_name' => $options['include'] ) ); while ( $the_query->have_posts() ): $the_query->the_post(); global $post; $id = $post->ID; $termsArray = get_the_terms( $id, 'category' ); $termsString = ""; if ( $termsArray) { foreach ( $termsArray as $term ) { $termsString .= $term->slug.' '; } } $project_title = '
'; $project_title .= '
'; $project_title .= ''.get_the_title($post->ID).''; $project_title .= '
'; $project_title .= '
'; if ( has_post_thumbnail() ) { $project_url = get_post_meta( get_the_ID(), 'wpcf-project-link', true ); if ( $project_url ) : $output .= ''; else : $output .= ''; endif; } endwhile; wp_reset_postdata(); $output .= '
'; $output .= '
'; $output .= '
'; echo $output; echo $args['after_widget']; } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['number'] = strip_tags($new_instance['number']); $instance['includes'] = sanitize_text_field($new_instance['includes']); $instance['show_filter'] = is_null( $new_instance['show_filter'] ) ? 0 : 1; $instance['show_project_title'] = is_null( $new_instance['show_project_title'] ) ? 0 : 1; $instance['show_all_text'] = sanitize_text_field($new_instance['show_all_text']); return $instance; } function form($instance) { $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; $number = isset( $instance['number'] ) ? intval( $instance['number'] ) : -1; $includes = isset( $instance['includes'] ) ? esc_attr($instance['includes']) : ''; $show_filter = isset( $instance['show_filter'] ) ? (bool) $instance['show_filter'] : true; $show_project_title = isset( $instance['show_project_title'] ) ? (bool) $instance['show_project_title'] : false; $show_all_text = isset( $instance['show_all_text'] ) ? esc_html($instance['show_all_text']) : __('Show all', 'sydney'); ?>

id="get_field_id( 'show_filter' ); ?>" name="get_field_name( 'show_filter' ); ?>" />

id="get_field_id( 'show_project_title' ); ?>" name="get_field_name( 'show_project_title' ); ?>" />