<?php
class WocaRecommendedPosts_Widget extends WP_Widget {
function WocaRecommendedPosts_Widget() {
$widget_ops = array( 'classname' => 'wrp-description', 'description' => 'Belirtilen kategorideki son yazıları gösterir.' );
$this->WP_Widget( 'woca-recommended-posts', __('Woca: Sizin İçin Seçtiklerimiz', 'wocathemes'), $widget_ops );
}
function widget( $args, $instance ) {
extract( $args, EXTR_SKIP );
$title = apply_filters('widget_title', $instance['title']);
echo $before_widget;
echo $before_title;
echo $title;
echo $after_title;
$number = (int)$instance['number'];
if(!$number)
$number = 5;
$woca_options = get_option( 'woca_options');
$wrp_args = array(
'cat' => $woca_options['cat_recommended_posts'],
'showposts' => $number
);
$wrp_transient = wrp_set_transient($wrp_args);
?>
<div id="recommended-posts">
<ul class="section">
<?php
$wrp_count = 0;
if ($wrp_transient):
foreach ($wrp_transient as $wrp) {
$wrp_count++;
print_r($wrp);// $wrp'de olan değerleri ekrana yazalım.
$title = $wrp['title'];
$permalink = $wrp['permalink'];
$thumbnail = $wrp['thumbnail'];
$categories = $wrp['categories'];
?>
<li
class="article recommendedTooltip <?php if($wrp_count % 2 != 0) echo "left"; ?>"
title="<p><b><?php echo $title; ?></b></p>
<p><b>Kategori:</b>
<?php foreach($categories as $category) {
$cat .= $category->name . ", ";
}
echo substr($cat, 0, -2);
$cat= "";
?>
</p>">
<figure>
<a href="<?php echo $permalink; ?>">
<?php if ( $thumbnail ) echo $thumbnail; ?>
</a>
</figure>
</li>
<?php } ?>
<?php endif; ?>
</ul>
<div id="pager"></div>
<div class="buttons">
<a href="#next" id="carouselbackbtn" class="prev"><?php _e('Önceki', 'wocathemes');?></a>
<a href="#prev" id="carouselnextbtn" class="next"><?php _e('Sonraki', 'wocathemes');?></a>
</div>
</div>
<?php
echo $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']);
return $instance;
}
function form( $instance ) {
$defaults = array('title' => 'Sizin İçin Seçtiklerimiz', 'number' => '5'); $instance = wp_parse_args((array) $instance, $defaults );
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Başlık:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $instance['title']; ?>" />
</p>
<p>
<input class="widefat" style="width: 30px;" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $instance['number']; ?>" />
<label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Gösterilecek yazı sayısı:', 'wocathemes'); ?></label>
</p>
<?php
}
}
add_action( 'widgets_init', create_function( '', "register_widget( 'WocaRecommendedPosts_Widget' );" ) );