add_panel( 'buzzo_home_page', array( 'title' => __( 'Home page', 'buzzo' ), 'priority' => 85, ) ); /* * Featured section. */ $wp_customize->add_section( 'buzzo_home_featured', array( 'title' => __( 'Featured section', 'buzzo' ), 'panel' => 'buzzo_home_page', ) ); // Featured category. $wp_customize->add_setting( 'buzzo_home_featured_cat', array( 'default' => 0, 'transport' => 'refresh', 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( 'buzzo_home_featured_cat', array( 'label' => __( 'Featured category', 'buzzo' ), 'section' => 'buzzo_home_featured', 'type' => 'select', 'choices' => $this->_get_option_cats(), ) ); // Featured background. $wp_customize->add_setting( 'buzzo_home_featured_bg_image', array( 'default' => '', 'transport' => 'refresh', 'sanitize_callback' => 'esc_url', ) ); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'buzzo_home_featured_bg_image', array( 'label' => __( 'Featured background image', 'buzzo' ), 'section' => 'buzzo_home_featured', ) ) ); // Number of posts. $wp_customize->add_setting( 'buzzo_home_featured_number', array( 'default' => 9, 'transport' => 'refresh', 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( 'buzzo_home_featured_number', array( 'label' => __( 'Number of posts', 'buzzo' ), 'section' => 'buzzo_home_featured', 'type' => 'text', ) ); foreach ( $this->_get_sections() as $section_name => $section_title ) { $this->_register_section_settings( $wp_customize, $section_name, $section_title ); } /* * Columns section. */ $wp_customize->add_section( 'buzzo_home_columns', array( 'title' => __( 'Columns section', 'buzzo' ), 'panel' => 'buzzo_home_page', ) ); // Show this section. $wp_customize->add_setting( 'buzzo_home_columns_show', array( 'default' => true, 'transport' => 'refresh', 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( 'buzzo_home_columns_show', array( 'label' => __( 'Show this section', 'buzzo' ), 'section' => 'buzzo_home_columns', 'type' => 'checkbox', ) ); // Columns layout. $wp_customize->add_setting( 'buzzo_home_columns_layout', array( 'default' => '1_1_1', 'transport' => 'refresh', 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'buzzo_home_columns_layout', array( 'label' => __( 'Columns layout', 'buzzo' ), 'section' => 'buzzo_home_columns', 'type' => 'select', 'choices' => $this->_get_option_columns_layout(), ) ); // Background color. $wp_customize->add_setting( 'buzzo_home_columns_bg_color', array( 'default' => '', 'transport' => 'refresh', 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'buzzo_home_columns_bg_color', array( 'label' => __( 'Background color', 'buzzo' ), 'section' => 'buzzo_home_columns', ) ) ); } /** * Register home column sidebar. */ public function register_column_sidebars() { register_sidebars( 3, array( /* translators: %s: Home colunm sidebar number */ 'name' => __( 'Home column %s', 'buzzo' ), 'id' => 'buzzo-home-column', 'description' => __( 'Use in section home columns', 'buzzo' ), 'class' => '', 'before_widget' => '
', 'before_title' => '', ) ); } /** * Register home section settings. * * @param object $wp_customize WP_Customize object. * @param string $section_name Section name. * @param string $section_title Section title. */ protected function _register_section_settings( $wp_customize, $section_name, $section_title ) { $section_id = 'buzzo_home_' . $section_name; $wp_customize->add_section( $section_id, array( 'title' => $section_title, 'panel' => 'buzzo_home_page', ) ); // Show this section. $wp_customize->add_setting( $section_id . '_show', array( 'default' => true, 'transport' => 'refresh', 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( $section_id . '_show', array( 'label' => __( 'Show this section', 'buzzo' ), 'section' => $section_id, 'type' => 'checkbox', ) ); // Title. $wp_customize->add_setting( $section_id . '[title]', array( 'default' => '', 'transport' => 'refresh', 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( $section_id . '[title]', array( 'label' => __( 'Title', 'buzzo' ), 'section' => $section_id, 'type' => 'text', ) ); // Category. $wp_customize->add_setting( $section_id . '[cat]', array( 'default' => 0, 'transport' => 'refresh', 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( $section_id . '[cat]', array( 'label' => __( 'Choose category', 'buzzo' ), 'section' => $section_id, 'type' => 'select', 'choices' => $this->_get_option_cats(), ) ); // Number of posts. $wp_customize->add_setting( $section_id . '[number]', array( 'default' => 9, 'transport' => 'refresh', 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( $section_id . '[number]', array( 'label' => __( 'Number of posts', 'buzzo' ), 'section' => $section_id, 'type' => 'text', ) ); // Show list categories. $wp_customize->add_setting( $section_id . '[show_list_cats]', array( 'default' => false, 'transport' => 'refresh', 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( $section_id . '[show_list_cats]', array( 'label' => __( 'Show list categories', 'buzzo' ), 'description' => __( 'Display list categories in the bottom of section title.', 'buzzo' ), 'section' => $section_id, 'type' => 'checkbox', ) ); // List categories. $wp_customize->add_setting( $section_id . '[list_cats]', array( 'default' => '', 'transport' => 'refresh', 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( $section_id . '[list_cats]', array( 'label' => __( 'List categories', 'buzzo' ), 'section' => $section_id, 'type' => 'text', 'active_callback' => $section_id . '_show_list_cats', ) ); // Show view more. $wp_customize->add_setting( $section_id . '[show_view_more]', array( 'default' => 'no', 'transport' => 'refresh', 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( $section_id . '[show_view_more]', array( 'label' => __( 'Show view more link', 'buzzo' ), 'section' => $section_id, 'type' => 'select', 'choices' => array( 'no' => __( 'Not show', 'buzzo' ), 'in_bottom' => __( 'In the bottom of section', 'buzzo' ), 'in_list_cats' => __( 'In list categories', 'buzzo' ), ), ) ); // View more text. $wp_customize->add_setting( $section_id . '[view_more_text]', array( 'default' => __( 'View more', 'buzzo' ), 'transport' => 'refresh', 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( $section_id . '[view_more_text]', array( 'label' => __( 'View more text', 'buzzo' ), 'section' => $section_id, 'type' => 'text', 'active_callback' => $section_id . '_show_view_more', ) ); // View more url. $wp_customize->add_setting( $section_id . '[view_more_url]', array( 'default' => '#', 'transport' => 'refresh', 'sanitize_callback' => 'esc_url', ) ); $wp_customize->add_control( $section_id . '[view_more_url]', array( 'label' => __( 'View more url', 'buzzo' ), 'section' => $section_id, 'type' => 'url', 'active_callback' => $section_id . '_show_view_more', ) ); // Title align. $wp_customize->add_setting( $section_id . '[title_align]', array( 'default' => 'left', 'transport' => 'refresh', 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( $section_id . '[title_align]', array( 'label' => __( 'Title align', 'buzzo' ), 'section' => $section_id, 'type' => 'select', 'choices' => array( 'left' => __( 'Left', 'buzzo' ), 'center' => __( 'Center', 'buzzo' ), 'right' => __( 'Right', 'buzzo' ), ), ) ); // Background color. $wp_customize->add_setting( $section_id . '[bg_color]', array( 'default' => '', 'transport' => 'refresh', 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $section_id . '[bg_color]', array( 'label' => __( 'Background color', 'buzzo' ), 'section' => $section_id, ) ) ); // Priority. $wp_customize->add_setting( $section_id . '[priority]', array( 'default' => 0, 'transport' => 'refresh', 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( $section_id . '[priority]', array( 'label' => __( 'Priority', 'buzzo' ), 'description' => __( 'Lowest priority will be shown first.', 'buzzo' ), 'section' => $section_id, 'type' => 'text', ) ); } /** * Get categories options. * * @return array */ protected function _get_option_cats() { $option_cats = get_categories( array( 'hide_empty' => false, 'fields' => 'id=>name', ) ); $option_cats = array( 0 => __( 'All categories', 'buzzo' ), ) + $option_cats; return $option_cats; } /** * Get sections options. * * @return array */ protected function _get_sections() { return array( 'grid' => __( 'Grid posts section', 'buzzo' ), 'carousel' => __( 'Carousel posts section', 'buzzo' ), 'grid_2' => __( 'Grid-2 posts section', 'buzzo' ), ); } /** * Get home columns layout options. * * @return array */ protected function _get_option_columns_layout() { $options = array( '1_1_1' => '1/3 + 1/3 + 1/3', '2_1' => '2/3 + 1/3', '1_2' => '1/3 + 2/3', '3' => '1/1', ); return apply_filters( 'buzzo_home_option_columns_layout', $options ); } /** * Get sections data. * * @return array */ public static function get_sections_data() { $sections = array(); $sections_name = array( 'grid', 'carousel', 'grid_2' ); foreach ( $sections_name as $name ) { if ( ! get_theme_mod( 'buzzo_home_' . $name . '_show', true ) ) { continue; } $sections[ $name ] = get_theme_mod( 'buzzo_home_' . $name, array() ); } uasort( $sections, array( __CLASS__, 'sort_sections' ) ); return apply_filters( 'buzzo_home_sections_data', $sections ); } /** * Sort sections callback by priority. * * @param array $section1 Section 1. * @param array $section2 Section 2. * @return int */ public static function sort_sections( $section1, $section2 ) { if ( ! isset( $section1['priority'] ) ) { $section1['priority'] = 0; } if ( ! isset( $section2['priority'] ) ) { $section2['priority'] = 0; } if ( $section1['priority'] == $section2['priority'] ) { return 0; } return $section1['priority'] < $section2['priority'] ? -1 : 1; } /** * Get home columns layout. * * @return string */ public static function get_home_columns_layout() { return get_theme_mod( 'buzzo_home_columns_layout', '1_1_1' ); } /** * Get home columns classes. * * @return array */ public static function get_home_columns_css_classes() { $layout = self::get_home_columns_layout(); $classes = array(); switch ( $layout ) { case '2_1': $classes = array( 'col-sm-8', 'col-sm-4' ); break; case '1_2': $classes = array( 'col-sm-4', 'col-sm-8' ); break; case '3': $classes = array( 'col-sm-12' ); break; default: $classes = array( 'col-sm-4', 'col-sm-4', 'col-sm-4' ); } return apply_filters( 'buzzo_home_columns_css_classes', $classes, $layout ); } } new Buzzo_Home_Page(); function buzzo_home_grid_show_list_cats() { $data = get_theme_mod( 'buzzo_home_grid' ); return ! empty( $data['show_list_cats'] ); } function buzzo_home_carousel_show_list_cats() { $data = get_theme_mod( 'buzzo_home_carousel' ); return ! empty( $data['show_list_cats'] ); } function buzzo_home_grid_2_show_list_cats() { $data = get_theme_mod( 'buzzo_home_grid_2' ); return ! empty( $data['show_list_cats'] ); } function buzzo_home_grid_show_view_more() { $data = get_theme_mod( 'buzzo_home_grid' ); return ! empty( $data['show_view_more'] ) && 'no' != $data['show_view_more']; } function buzzo_home_carousel_show_view_more() { $data = get_theme_mod( 'buzzo_home_carousel' ); return ! empty( $data['show_view_more'] ) && 'no' != $data['show_view_more']; } function buzzo_home_grid_2_show_view_more() { $data = get_theme_mod( 'buzzo_home_grid_2' ); return ! empty( $data['show_view_more'] ) && 'no' != $data['show_view_more']; } if ( ! function_exists( 'buzzo_featured_section' ) ) { /** * Display featured posts section. */ function buzzo_featured_section() { $query_args = array( 'posts_per_page' => get_theme_mod( 'buzzo_home_featured_number', 9 ), 'ignore_sticky_posts' => true, ); if ( get_theme_mod( 'buzzo_home_featured_cat' ) ) { $query_args['cat'] = get_theme_mod( 'buzzo_home_featured_cat' ); } $query = new WP_Query( $query_args ); if ( ! $query->have_posts() ) { return; } ?>