Code phân trang danh mục wordpress không cần plugin
5 năm trước,
Code theme wordpress,
1165 Lượt xem
Đây là đoạn code phân trang cho danh mục không cần dùng plugin
Nội dung
code cho file function
//Code phan trang
function netweb_wp_corenavi($custom_query = null, $paged = null) {
global $wp_query;
if($custom_query) $main_query = $custom_query;
else $main_query = $wp_query;
$paged = ($paged) ? $paged : get_query_var('paged');
$big = 999999999;
$total = isset($main_query->max_num_pages)?$main_query->max_num_pages:'';
if($total > 1) echo '<div class="pagenavi">';
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, $paged ),
'total' => $total,
'mid_size' => '3', // Số trang hiển thị khi có nhiều trang trước khi hiển thị ...
'prev_text' => __('Trở về','netweb'),
'next_text' => __('Tiếp','netweb'),
) );
if($total > 1) echo '</div>';
}
Hiển thị phân trang cho danh mục
<?php
$the_press = new WP_Query(array('post_type' => 'post','posts_per_page' => 10,'cat' => get_query_var('cat'), 'paged'=> get_query_var('paged') ));
// The Loop
while ($the_press->have_posts()) : $the_press->the_post();
?>
<div class="row boxtinok">
<div class="post-item-bv wow fadeInUp">
<div class="post-detail">
<a href="<?php echo the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
</div>
<h5 class="post-title-gory"><a href="<?php echo the_permalink(); ?>"><?php the_title(); ?></a></h5>
<p class="excerpt-gory"><?php the_excerpt(); ?>
</p>
</div>
</div>
<?php endwhile; ?>
<?php if (function_exists('netweb_wp_corenavi')) netweb_wp_corenavi($the_press); ?>
<?php wp_reset_postdata();?>
Css cho phân trang
.pagenavi{
margin: 13px 0px;
}
.pagenavi a:hover {
color: #fff;
background: #359c6a;
}
.pagenavi .current{color: #fff;background: #359c6a;}
span.page-numbers.current {}
page-numbers a:hover {
}
.pagenavi .page-numbers{border:1px solid #DDD;padding: 5px 11px;/* border-radius: 8px; */}
Bài viết mới cập nhập
Chủ đề liên quan theo Tag





Bình luận trên facebook netweb.vn