Nội dung

Code phân trang danh mục wordpress không cần plugin

4 năm trước, Code theme wordpress, 1068 Lượt xem

Đây là đoạn code phân trang cho danh mục không cần dùng plugin

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

  • Hướng dẫn Plugin floating contact

    Hướng dẫn Plugin floating contact

    1 năm trước, 380 Lượt xem

    Netweb xin hướng dẫn cách quản lý Plugin floating contact các bạn nhớ làm theo kỹ tường bước để plugin hoạt động Tính năng: Hiển…

  • Backup Yandex Mail

    Backup Yandex Mail

    1 năm trước, 251 Lượt xem

    Khác với dịch vụ email theo tên của microsoft và google với chi phí đắt đỏ tầm 1tr/năm/1user, vì thế nên netweb khuyên dùng dịch…

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

Chủ đề liên quan theo Tag

Đam mê thiết kế web, kinh nghiệm 9 năm trong nghề thiết kế website, đang thiết kế web dạo tại netweb.vn, Callme: 08.9898.2526 (Mr Hải)