Merhaba arkadaşlar. aşağıdaki kodlarda son 5 kayıtı listelemek istiyorum nasıl yapabilirim. Birde geri kalan kayıtları altta 1.2.3 sayfa diye ayırabilir miyim ?
İyi çalışmalar.
<?php
add_action('widgets_init', 'kose_yazarlari_bilesen');
function kose_yazarlari_bilesen() {
register_widget('KoseYazarlariBileseni');
}
class KoseYazarlariBileseni extends WP_Widget
{
public function __construct()
{
parent::__construct( 'columnist', 'Semantik Haber Köşe Yazarları', array(
'classname' => 'columnist',
'description' => 'Sitenizde yer alan yazarları bu bileşeni aktif ederek listeleyebilirsiniz.',
'width' => 300,
'height' => 350
) );
add_action( 'save_post', array( $this, 'koseyazarlari_cache_temizle' ) );
add_action( 'deleted_post', array( $this, 'koseyazarlari_cache_temizle' ) );
add_action( 'switch_theme', array( $this, 'koseyazarlari_cache_temizle' ) );
}
public function widget( $args, $instance )
{
extract( $args );
//echo $before_widget;
$code = get_transient( $this->id );
if( $code === false )
{
$defaults = $this->get_defaults();
extract( wp_parse_args( $instance, $defaults ) );
if (!$title){
$baslik = 'KÖŞE YAZARLARI';
} else {
$baslik = $title;
}
$code = '';
$code .='<div class="blok-2">
<div class="bslk">
<span>'.$baslik.'</span>
</div>
<div class="icerik">';
$blogusers = get_users_of_blog();
if ($blogusers) {
foreach ($blogusers as $bloguser) {
$user = get_userdata($bloguser->user_id);
$level = $user->user_level;
if($level == 7) {
$code .='<div class="yazar yczgi">';
$avatar = get_user_meta($bloguser->user_id, 'uyeresim', true);
if($avatar) {
$code .='<ul class="sol">
<li>
<a href="'.get_author_posts_url( $user->ID ).'" title="' . $user->user_firstname . $user->user_lastname . ' tarafından yayınlanan yazılar">
<img src="'. $avatar.'" alt="' . $user->user_firstname . $user->user_lastname . '" width="96" height="93" />
</a>
</li>
</ul>';
}
$code .='<ul class="sag">
<li class="yisim"><a href="'.get_author_posts_url( $user->ID ).'" title="' . $user->user_firstname . $user->user_lastname . ' tarafından yayınlanan yazılar">' . $user->user_firstname . ' '. $user->user_lastname . '</a></li>';
$yargs = array(
'author' => $user->ID,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1,
'showposts' => 1
);
$kyazar_q = null;
$kyazar_q = new WP_Query($yargs);
if( $kyazar_q->have_posts() ) {
while ( $kyazar_q->have_posts() ) {
$kyazar_q->the_post();
$code .='<li class="ybslk">
<a href="'.get_permalink().'" rel="bookmark" title="'.get_the_title().'">'.get_the_title().'</a>
</li>';
$code .='<li class="ytarih">
'.get_the_time('j F Y').'- '. get_the_time('H:i:s').'
</li>';
}
wp_reset_query();
}
$code .='</ul><div style="clear:both;"></div>';
$code .='</div>';
}
}
}
$code .='</div>
<div class="bosluk"></div>
</div>
<div class="bosluk2"></div>';
set_transient( $this->id, $code, DAY_IN_SECONDS );
}
echo $code;
//echo $after_widget;
}
public function form( $instance )
{
$defaults = $this->get_defaults();
extract( wp_parse_args( $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' ); ?>" value="<?php echo esc_attr( $title ); ?>" class="widefat" />
</p>
<?php
}
public function update( $new_instance, $old_instance )
{
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['number'] = absint( $new_instance['number'] );
$this->koseyazarlari_cache_temizle();
return $instance;
}
private function get_defaults()
{
$defaults = array(
'title' => 'KÖŞE YAZARLARI',
'number' => 5,
);
return $defaults;
}
public function koseyazarlari_cache_temizle()
{
delete_transient( $this->id );
}
}