<?php
$nav_type = get_op('post_nav','btn');

?>

<div class="cls-blog-cat-filter">
    <?php echo post_cat_filter(); ?>
</div>


<div id="blog-item" class="p-item box-p" >

    <?php

        /* if ( have_posts() ) :

            while ( have_posts() ) :
            
                the_post();
                
                get_template_part( 'tpl/content' );
                
            endwhile;
            
        else :

            get_template_part( 'tpl/content', 'none' );

        endif; */

        $cat = get_cu('cls_show_cats_de','0');

        $args = array(
            'post_type' => 'post', 
            'post_status' => 'publish',
            //'cat' => $cat,
            //'paged' => 5
            );

        if($cat != '0'){
            $args['cat'] = $cat;
        }    
                 
        $my_query = new WP_Query($args);
        
        if( $my_query->have_posts() ) {

            while ($my_query->have_posts()) : $my_query->the_post();

            get_template_part( 'tpl/content');

            endwhile; 
            wp_reset_postdata(); 
        }
        
        //print_r($my_query);
        $max = $my_query->max_num_pages;
        $cat = get_cu('cls_show_cats_de','0');
    ?>

</div>

<?php if($nav_type == 'btn' || $nav_type == 'scroll') { ?>
<div class="pagenav-box">
    <div class="number-pager">
        <div class="pager-info">
            <div class="paged-number">当前：<span class="current">1</span> / <span class="total"><?php echo $max ?></span></div>
            <div class="go-top"><a class="hint--top hint--rounded" href="#page" uk-scroll data-hint="回到顶部"><i class="ri-arrow-up-line"></i></a></div>
        </div>
    </div>
    <?php if ( $my_query->max_num_pages > 1 ){ ?>
        <div class="load-more-box">
            <div class="loadmore-btn" data-paged="1" data-action="cls_load_posts" data-append="#blog-item" data-max="<?php echo $max ?>" data-cat="<?php echo $cat ?>">加载更多</div>
        </div>   
    <?php } ?>
     
</div>

<?php } else { ?>

    <div class="pagination-box" data-action="cls_load_posts" data-cat="<?php echo $cat ?>" data-max="<?php echo $max ?>" data-append="#blog-item" > 
    <?php 
        $paged = max(1, get_query_var('paged'));
        echo paginate_links(array(
            'base' => str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))),
            'format' => '?paged=%#%',
            'current' => $paged,
            'total' => $max,
            'prev_text' => '上一页',
            'next_text' => '下一页',
            'type' => 'list'
        ));
    
        ?>
    </div>

<?php } ?>