İlk istediğiniz için;
<?php
add_action('widgets_init', 'themeloy_register_widgets_grid_list');
function themeloy_register_widgets_grid_list() {
register_widget('themeloy_recent_posts_widget_grid_list');
}
class themeloy_recent_posts_widget_grid_list extends WP_Widget {
/*-----------------------------------------------------------------------------------*/
/* Widget Setup
/*-----------------------------------------------------------------------------------*/
function __construct() {
$widget_ops = array(
'classname' => 'cat_recent_entries clearfix',
'description' => __('Ekran ızgara veya ön sayfada bir veya birden fazla kategoriden gelen son mesajları listeler.', 'tl_back')
);
parent::__construct('custom-recent-posts-grid-list', __('Klavyer: Ana Sayfa Bileşeni NO:1', 'tl_back'), $widget_ops);
}
/*-----------------------------------------------------------------------------------*/
/* Display Widget
/*-----------------------------------------------------------------------------------*/
function widget($args, $instance) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? 'Recent Posts' : $instance['title'], $instance, $this->id_base);
$show_style_1 = isset($instance['show_style_1']) ? $instance['show_style_1'] : false;
if (!$number = absint($instance['number']))
$number = 4;
if (!$cats = $instance["cats"])
$cats = '';
// array to call recent posts.
$themeloy_args = array(
'showposts' => $number,
'category__in' => $cats,
);
$themeloy_widget = null;
$themeloy_widget = new WP_Query($themeloy_args);
echo $before_widget;
// Widget title
echo $before_title;
echo $instance["title"];
echo $after_title;
// Post list in widget
$blog_date_widget = of_get_option('blog_date_widget', 0);
$blog_comment_widget = of_get_option('blog_comment_widget', 0);
$i = 0;
while ($themeloy_widget->have_posts()) {
$themeloy_widget->the_post();
$i++;
$thumb = get_post_thumbnail_id(get_the_ID());
if (!$thumb) {
$url[0] = get_template_directory_uri() . '/img/demo/dum-2.jpg';
}else{
$url = wp_get_attachment_image_src( $thumb , '177x100');
}
$date = '<span class="date">' . get_the_date('M d, Y') . '</span>';
?>
<div class="small-feature">
<div id="klavyer-icon">
<a href="<?php the_permalink(); ?>" class="feature-link"><img src="<?php echo $url[0]; ?>" alt="<?php the_title(); ?>" />
<?php echo themeloy_post_type(); ?>
<span class="goster-1-2"></span>
</div>
</a>
<div class="feature-text">
<div class="post-title"><h4><a class="title" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php echo themeloy_short_title(50, get_the_title('')); ?>
</a></h4>
</div>
<?php if($blog_date_widget == 0) { ?>
<?php } ?>
<?php if($blog_comment_widget == 0) { ?><?php } ?>
<?php $enable_review = get_post_custom_values('reviewthemeloy_checkbox', get_the_ID()); ?>
<?php if (of_get_option('disable_review') == 0){
if($enable_review[0] == 1){?>
<span class="review-star">
<span style="width:<?php echo themeloy_get_total_review(get_the_ID()); ?>%" class="review-star-inline"></span>
</span>
<?php }else{?>
<span class="review-star-none">
<span class="review-star-inline-none"></span>
</span>
<?php }}else{?>
<span class="review-star-none">
<span class="review-star-inline-none"></span>
</span>
<?php } ?>
</div>
<?php
foreach((get_the_category()) as $category) {
$cikti = $category->slug;
}
?>
<div class="isim-d-<?php echo $cikti; ?>"></div><div class="isim-<?php echo $cikti; ?>"></div>
<div id="tarih-ana-alt">
<i class="post-meta-ic"><?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' önce'; ?></i>
</div>
</div>
<?php
}
?>
</div>
<?php
wp_reset_query();
echo $after_widget;
}
/*-----------------------------------------------------------------------------------*/
/* Update Widget
/*-----------------------------------------------------------------------------------*/
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['cats'] = $new_instance['cats'];
$instance['number'] = absint($new_instance['number']);
$instance['show_style_1'] = (bool) $new_instance['show_style_1'];
return $instance;
}
/*-----------------------------------------------------------------------------------*/
/* Widget Settings (Displays the widget settings controls on the widget panel)
/*-----------------------------------------------------------------------------------*/
function form($instance) {
$title = isset($instance['title']) ? esc_attr($instance['title']) : 'Recent Posts';
$number = isset($instance['number']) ? absint($instance['number']) : 5;
$show_style_1 = isset($instance['show_style_1']) ? (bool) $instance['show_style_1'] : false;
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'tl_back'); ?></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 $title; ?>" /></p>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:', 'tl_back'); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
<p><input class="checkbox" type="checkbox" <?php checked($show_style_1); ?> id="<?php echo $this->get_field_id('show_style_1'); ?>" name="<?php echo $this->get_field_name('show_style_1'); ?>" />
<label for="<?php echo $this->get_field_id('show_style_1'); ?>"><?php _e('Display post feature below main post?', 'tl_back'); ?></label></p>
<p>
<label for="<?php echo $this->get_field_id('cats'); ?>"><?php _e('Select categories to include in the recent posts list:', 'tl_back'); ?>
<?php
$categories = get_categories('hide_empty=0');
echo "<br/>";
foreach ($categories as $cat) {
$option = '<input type="checkbox" id="' . $this->get_field_id('cats') . '[]" name="' . $this->get_field_name('cats') . '[]"';
if (isset($instance['cats'])) {
foreach ($instance['cats'] as $cats) {
if ($cats == $cat->term_id) {
$option = $option . ' checked="checked"';
}
}
}
$option .= ' value="' . $cat->term_id . '" />';
$option .= ' ';
$option .= $cat->cat_name;
$option .= '<br />';
echo $option;
}
?>
</label>
</p>
<?php
}
}
?>2. istediğiniz widget için functions.php'nize şu kodları ekleyin;
class Yazi_ici_Benzer_Yazilar extends WP_Widget {
function __construct() {
parent::__construct(
'yazi_ici_benzer_yazilar',
'Yazı içinde benzer yazılar',
array( 'description' => 'Yazı sayfasında benzer yazıları gösterir.(Etikete göre)', )
);
}
public function widget( $args, $instance ) {
global $post;
$tags = wp_get_post_tags($post->ID);
if(is_single() && $tags){
$title = apply_filters( 'widget_title', $instance['title'] );
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args = array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'showposts' => 4 // kaç tane gösterilsin
);
echo $args['before_widget'];
if ( ! empty( $title ) ) {
echo $args['before_title'] . $title . $args['after_title'];
}
echo '<div class="widget recent-posts">';
echo '<ul class="ulpost">';
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<li>
<div class="yazi-tarih"><div class="yazi-tarih-ic">
<i class="icon-calendar"></i>
<i class="post-meta-ic"><?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' önce yazıldı'; ?></i>
</div></div>
<?php
$thumb = get_post_thumbnail_id(get_the_ID());
if (!$thumb) {
$url[0] = get_template_directory_uri() . '/img/demo/dum-6.jpg';
}else{
$url = wp_get_attachment_image_src( $thumb , '300x170');
}
echo '
<div id="klavyer-icon">
<a class="entry-thumb2 feature-link" href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '">
<img src="' . $url[0] . '" alt="' . get_the_title() . '" />
<span class="goster"></span>
</a>
</div>
';
echo themeloy_post_type();
?>
<div class="ulpost_title">
<a class="title" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php echo themeloy_short_title(61, get_the_title('')); ?>
</a>
<?php $enable_review = get_post_custom_values('reviewthemeloy_checkbox', get_the_ID()); ?>
<?php if (of_get_option('disable_review') == 0){
if($enable_review[0] == 1){?>
<span class="review-star">
<span style="width:<?php echo themeloy_get_total_review(get_the_ID()); ?>%" class="review-star-inline"></span>
</span>
<?php }else{?>
<span class="review-star-none">
<span class="review-star-inline-none"></span>
</span>
<?php }}else{?>
<span class="review-star-none">
<span class="review-star-inline-none"></span>
</span>
<?php } ?>
<?php
foreach((get_the_category()) as $category) {
$cikti = $category->slug;
}
?>
<div class="isim-d-<?php echo $cikti; ?>"></div><div class="isim-<?php echo $cikti; ?>"></div>
</div>
</li>
<?php
}
wp_reset_query();
echo "</ul>\n";
echo "</div>\n";
}
echo $args['after_widget'];
}
}
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'New title', 'text_domain' );
}
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></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 esc_attr( $title ); ?>">
</p>
<?php
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
}
add_action( 'widgets_init', function(){
register_widget( 'Yazi_ici_Benzer_Yazilar' );
});