WordPress Görünüm => Özelleştir alanına kategori seç bölümü eklemek için öncelikle kategoriler.php adında bir dosya oluşturalım. İçine aşağıdaki kodları yerleştirelim.
<?php add_action( 'customize_register', 'tema_manset_customize_register' ); function tema_manset_customize_register( WP_Customize_Manager $wp_customize ) { require_once get_stylesheet_directory() . '/inc/admin/kategori-sec.php'; $wp_customize->add_section( 'anasayfa', array( 'title' => esc_html_x( 'Kategoriler', 'customizer section title', 'temaadi' ), ) ); $wp_customize->add_setting( 'anasayfa_manset_kategori', array( 'default' => 0, 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( new My_Dropdown_Category_Control( $wp_customize, 'anasayfa_manset_kategori', array( 'section' => 'anasayfa', 'label' => esc_html__( 'Manşet Kategorisi', 'temaadi' ), 'description' => esc_html__( 'Manşet alanı için kategori seç', 'temaadi' ), ) ) ); }
Daha sonra kategori-sec.php adında bir dosya oluşturalım ve içine aşağıdaki kodları yerleştirelim.
<?php class My_Dropdown_Category_Control extends WP_Customize_Control { public $type = 'dropdown-category'; protected $dropdown_args = false; protected function render_content() { ?><label><?php if ( ! empty( $this->label ) ) : ?><span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span><?php endif; if ( ! empty( $this->description ) ) : ?><span class="description customize-control-description"><?php echo $this->description; ?></span><?php endif; $dropdown_args = wp_parse_args( $this->dropdown_args, array( 'taxonomy' => 'category', 'show_option_none' => ' ', 'selected' => $this->value(), 'show_option_all' => '', 'orderby' => 'id', 'order' => 'ASC', 'show_count' => 1, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'hierarchical' => 1, 'depth' => 0, 'tab_index' => 0, 'hide_if_empty' => false, 'option_none_value' => 0, 'value_field' => 'term_id', ) ); $dropdown_args['echo'] = false; $dropdown = wp_dropdown_categories( $dropdown_args ); $dropdown = str_replace( '<select', '<select ' . $this->get_link(), $dropdown ); echo $dropdown; ?></label><?php } }
Bunların kullanımı ise şöyledir;
<?php get_theme_mod( 'anasayfa_manset_kategori', 'temaadi' ); ?>
Bu kodu temada kategorideki yazıları göstermek istediğiniz yere yapıştırınız.
Bu arada functions.php ye [php]<?php [/php] den sonra
require_once get_template_directory() .'/dosya/kategoriler.php';
yukarıdaki yolu ekleyiniz. yoksa kategori alanı özelleştir bölümünde gözükmez.
/dosya/kategoriler.php yolunu da kendinize göre düzenleyiniz.
Kategori eklemek için kategoriler.php dosyasını kullanmalısınız. Yukarıda örnek bir kategori eklenmiştir. Manşet kategorisi örnek olarak verilmiştir. Siz de örnekteki gibi kategori ekleyebilirsiniz.