在Wordpress最新帖子小部件中,我想添加分页
public function widget($args, $instance) {
extract($args);
$title = apply_filters('widget_title', $instance['title'] );
$count = $instance['count'];
$category = $instance['category'];
echo $before_widget;
$output = '';
if ( $title )
echo $before_title . $title . $after_title;
global $post;
if ( isset( $category ) && $category != '' ) {
$args = array(
'category_name' => $category,
'posts_per_page' => $count,
);
} else {
$args = array(
'posts_per_page' => $count,
);
}
$posts = get_posts( $args );
if(count($posts)>0){
$output .='<div class="sp-latest-posts-widget latest-posts">';
foreach ($posts as $post): setup_postdata($post);
$output .='<div class="media">';
if(has_post_thumbnail()):
$output .='<div class="pull-left">';
$output .='<a href="'.get_permalink().'">'.get_the_post_thumbnail($post->ID, 'xs-thumb', array('class' => 'img-responsive')).'</a>';
$output .='</div>';
endif;
$output .='<div class="media-body">';
$output .= '<h3 class="entry-title"><a href="'.get_permalink().'">'. get_the_title() .'</a></h3>';
$output .= '<div class="entry-meta small"><span class="st-lp-time">'. get_the_time() . '</span> <span clss="st-lp-date">' . get_the_date('d M Y') . '</span></div>';
$output .='</div>';
$output .='</div>';
endforeach;
wp_reset_query();
$output .='</div>';
}
echo $output;
echo $after_widget;
}
&#13;
答案 0 :(得分:0)
使用以下代码编号分页,
<?php the_posts_pagination( array(
'mid_size' => 1,
'prev_text' => __( 'Prev', 'textdomain' ),
'next_text' => __( 'Next', 'textdomain' ),
'screen_reader_text' => ' ',
) );
} ?>