Bununla ilgili biraz arama yaptım fakat bulduğum kodlar eskiydi veya ben düzenleyemedim.
Bileşen olarak kullanıyorum ve kullandığım bileşenin kodları ise aşağıdaki gibi. Burada ne yapmam gerekiyor? Alt kategoriler ana kategorinin altında olsun fakat ana kategoriye tıklanınca aşağı açılsın.
Yardımcı olursanız memnun olurum şimdiden teşekkürler.
<?php
class Sidebar_category extends WP_Widget {
//Widget İnit
public function __construct() {
parent::__construct(
'sidebar_category',
'# Teknobit: Sidebar - Kategori Bileşeni',
array('description' => 'Kategori Bileşeni')
);
}
// Output the widget options in the back-end
public function form($instance) {
$defaults = array(
'title' => '',
'icon' => '',
'color' => '',
'number_type' => '',
'number_p' => '',
);
$instance = wp_parse_args((array) $instance, $defaults);
?>
<p>
<label for="<?php echo $this->get_field_id('title') ?>">Başlık:</label>
<input type="text" id="<?php echo $this->get_field_id('title') ?>" name="<?php echo $this->get_field_name('title') ?>" class="widefat" value="<?php echo esc_attr($instance['title']); ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('icon') ?>">İkon:</label>
<input type="text" id="<?php echo $this->get_field_id('icon') ?>" name="<?php echo $this->get_field_name('icon') ?>" class="widefat" value="<?php echo esc_attr($instance['icon']); ?>" placeholder="fa fa-bars"/>
</p>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#widgets-right .color-picker, .inactive-sidebar .color-picker').wpColorPicker();
$(document).ajaxComplete(function() {
$('#widgets-right .color-picker, .inactive-sidebar .color-picker').wpColorPicker();
});
});
</script>
<input class="color-picker" id="<?php echo $this->get_field_id( 'color' ); ?>" type="text" name="<?php echo $this->get_field_name( 'color' ); ?>" value="<?php if(esc_attr($instance['color'] == "")):echo ot_get_option('main-color');else :echo esc_attr($instance['color']);endif;?>" data-default-color="<?php echo ot_get_option('main-color'); ?>" />
<p>
<label for="<?php echo $this->get_field_id('number_p') ?>">Yazı Sayısı:</label>
<select id="<?php echo $this->get_field_id('number_p') ?>" name="<?php echo $this->get_field_name('number_p') ?>" class="widefat">
<option value="">Tür Seçiniz</option>
<option value="show_number" <?php echo esc_attr($instance['number_p']) == 'show_number' ? 'selected="selected"': null; ?>>Sayıları Göster</option>
<option value="hide_number" <?php echo esc_attr($instance['number_p']) == 'hide_number' ? 'selected="selected"': null; ?>>Sayıları Gizle</option>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('number_type') ?>">Listeleme Biçimi:</label>
<select id="<?php echo $this->get_field_id('number_type') ?>" name="<?php echo $this->get_field_name('number_type') ?>" class="widefat">
<option value="">Tür Seçiniz</option>
<option value="show" <?php echo esc_attr($instance['number_type']) == 'show' ? 'selected="selected"': null; ?>>Tüm Kategorileri Göster</option>
<option value="hide" <?php echo esc_attr($instance['number_type']) == 'hide' ? 'selected="selected"': null; ?>>Yalnız Yazı Olanları Göster</option>
</select>
</p>
<?php
}
// Process widget options for saving
public function update($new_instance, $old_instance) {
$instance = $old_instance;
//xxx
$instance['title'] = $new_instance['title'];
$instance['icon'] = $new_instance['icon'];
$instance['color'] = $new_instance['color'];
$instance['number_type'] = $new_instance['number_type'];
$instance['number_p'] = $new_instance['number_p'];
return $instance;
}
//Displays the widget on the page
public function widget($args, $instance) {
extract($args);
$title = $instance['title'];
$icon = $instance['icon'];
$color = $instance['color'];
$number_type = $instance['number_type'];
$number_p = $instance['number_p'];
?>
<div class="widget-container">
<div class="widget-title" style="background-color:<?php echo $color;?>"><span class="title-in"><?php echo $title;?></span> <?php if($icon):?><i class="<?php echo $icon; ?>" style="<?php if(ot_get_option('widget-title') == '2-tip'){ ?>background-color:<?php echo $color;?><?php }?>"></i><?php endif; ?></div>
<div class="widget-list-cat">
<ul>
<?php
switch ($number_type) {
case 'show':
$parametre = array (
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0
);
break;
case 'hide':
$parametre = array (
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1
);
break;
}
$kategoriler = get_categories($parametre);
foreach ($kategoriler as $kategori) :
$cat_ID = $kategori->term_id;
$cat_name = $kategori->name;
$cat_count = $kategori->count;
$term_meta = get_option( "taxonomy_$cat_ID" );
$cat_icon = $term_meta['icon'];
?>
<li><a href="<?php echo get_category_link($cat_ID);?>"><i class="<?php if(empty($cat_icon)){echo "fa fa-bars";}else{echo $cat_icon;} ?>"></i> <?php echo $cat_name;?> <?php if($number_p == "show_number") : ?><span class="count"><?php echo $cat_count; ?></span><?php endif;?></a></li>
<?php endforeach;?>
</ul>
</div>
</div>
<?php
}
}
register_widget('Sidebar_category');
?>