Aşağıdaki sidebar bileşenine ait koda kategori filtresi ekleyerek Kategori ID'si üzerinden bir kategoriyi hariç tutmak istiyorum. Nasıl yapabilirim?
<?php
/*
* Created by Pixel-Mafia
* www.pixel-mafia.com
*/
class aurel_featured_posts extends WP_Widget
{
public function __construct()
{
parent::__construct(
'aurel_featured_posts',
'Featured Posts (PM)',
array('description' => '')
);
}
public function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = esc_attr($new_instance['title']);
$instance['number_of_posts'] = absint($new_instance['number_of_posts']);
$instance['featured_images'] = esc_attr($new_instance['featured_images']);
$instance['post_meta'] = esc_attr($new_instance['post_meta']);
$instance['orderby'] = esc_attr($new_instance['orderby']);
return $instance;
}
public function form($instance)
{
$default_values = array(
'title' => esc_html__('Featured Posts', 'aurel'),
'number_of_posts' => '2',
'featured_images' => 'enabled',
'post_meta' => 'enabled',
'orderby' => 'date'
);
$instance = wp_parse_args((array)$instance, $default_values);
?>
<p class="aurel_widget">
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>">
<?php echo esc_html__('Title', 'aurel'); ?>:
</label>
<input class="widefat"
type="text"
id="<?php echo esc_attr($this->get_field_id('title')); ?>"
name="<?php echo esc_attr($this->get_field_name('title')); ?>"
value="<?php echo esc_html($instance['title']); ?>"
/>
<label for="<?php echo esc_attr($this->get_field_id('number_of_posts')); ?>">
<?php echo esc_html__('Number of Posts', 'aurel'); ?>:
</label>
<select name="<?php echo esc_attr($this->get_field_name('number_of_posts')); ?>"
id="<?php echo esc_attr($this->get_field_id('number_of_posts')); ?>">
<option value="2" <?php selected(absint($instance['number_of_posts']), 2); ?>>2</option>
<option value="3" <?php selected(absint($instance['number_of_posts']), 3); ?>>3</option>
<option value="4" <?php selected(absint($instance['number_of_posts']), 4); ?>>4</option>
<option value="5" <?php selected(absint($instance['number_of_posts']), 5); ?>>5</option>
<option value="6" <?php selected(absint($instance['number_of_posts']), 6); ?>>6</option>
</select>
<label for="<?php echo esc_attr($this->get_field_id('featured_images')); ?>">
<?php echo esc_html__('Featured Images', 'aurel'); ?>:
</label>
<select name="<?php echo esc_attr($this->get_field_name('featured_images')); ?>"
id="<?php echo esc_attr($this->get_field_id('featured_images')); ?>">
<option value="enabled" <?php selected($instance['featured_images'], 'enabled'); ?>>Enabled</option>
<option value="disabled" <?php selected($instance['featured_images'], 'disabled'); ?>>Disabled</option>
</select>
<label for="<?php echo esc_attr($this->get_field_id('post_meta')); ?>">
<?php echo esc_html__('Post Meta', 'aurel'); ?>:
</label>
<select name="<?php echo esc_attr($this->get_field_name('post_meta')); ?>"
id="<?php echo esc_attr($this->get_field_id('post_meta')); ?>">
<option value="enabled" <?php selected($instance['post_meta'], 'enabled'); ?>>Enabled</option>
<option value="disabled" <?php selected($instance['post_meta'], 'disabled'); ?>>Disabled</option>
</select>
<label for="<?php echo esc_attr($this->get_field_id('orderby')); ?>">
<?php echo esc_html__('Order By', 'aurel'); ?>:
</label>
<select name="<?php echo esc_attr($this->get_field_name('orderby')); ?>"
id="<?php echo esc_attr($this->get_field_id('orderby')); ?>">
<option value="date" <?php selected($instance['orderby'], 'date'); ?>>Date</option>
<option value="rand" <?php selected($instance['orderby'], 'rand'); ?>>Random</option>
</select>
</p>
<?php
}
public function widget($args, $instance)
{
extract($args);
echo $before_widget;
if ($instance['title']) {
echo $before_title;
echo apply_filters('widget_title', $instance['title']);
echo $after_title;
}
$args = array(
'post_type' => 'post',
'orderby' => esc_attr($instance['orderby']),
'post_status' => 'publish',
'posts_per_page' => absint($instance['number_of_posts']),
);
query_posts($args);
if (have_posts()) {
echo '<div class="aurel_recent_posts aurel_items_' . absint($instance['number_of_posts']) . '">';
while (have_posts()) {
the_post();
echo '
<div class="aurel_posts_item ' . ((aurel_get_featured_image_url() && esc_attr($instance['featured_images']) == 'enabled') ? 'aurel_block_with_fi' : 'aurel_block_without_fi') . ' ' . (($instance['featured_images'] == 'disabled' && $instance['post_meta'] == 'disabled') ? 'aurel_simple_list' : '') . '">
' . ((aurel_get_featured_image_url() && esc_attr($instance['featured_images']) == 'enabled') ? '<a href="' . esc_url(get_permalink()) . '" class="aurel_posts_item_image aurel_dp aurel_no_select"><img class="aurel_fimage" src="' . esc_url(aq_resize(aurel_get_featured_image_url(), 150, 150, true, true, true)) . '" alt="" /></a>' : '') . '
<div class="aurel_posts_item_content">
<a class="aurel_featured_post_widget_title" href="' . esc_url(get_permalink()) . '">' . esc_attr(get_the_title()) . '</a>';
if (esc_attr($instance['post_meta']) == 'enabled') {
?>
<div class="aurel_widget_meta">
<div><?php echo get_the_date(); ?></div>
</div>
<?php
}
echo '
</div>
</div>
';
}
wp_reset_query();
echo '</div>';
}
echo $after_widget;
}
}
add_action('widgets_init', 'aurel_featured_posts_init');
function aurel_featured_posts_init() {
register_widget('aurel_featured_posts');
}