页码分页

2023-12-25 1次

<?php
function get_pagenavi($range = 2)
{
    global $paged, $wp_query;
    if (isset($max_page)) {
       
    }else{
         $max_page = $wp_query->max_num_pages;
    }
    if ($max_page > 1) {
        if (!$paged) {
            $paged = 1;
        }
        ?>
        <ul class="flex">
            <?php
            if (get_previous_posts_link()) {
                ?>
                <li class="paging-link paging-prev">
                    <?php previous_posts_link(' '); ?>
                </li>
                <?php
            } else { ?>
                <li class="paging-link paging-prev">
                    <a href="javascript:;"></a>
                </li>
            <?php }
            if ($max_page > $range) {
                if ($paged < $range) {
                    for ($i = 1; $i <= ($range + 1); $i++) { ?>
                        <li class="paging-link">
                            <a href="<?php echo get_pagenum_link($i); ?> " <?php if ($i == $paged) { ?>class="current" <?php } ?>>
                                <?php echo $i; ?>
                            </a>
                        </li>
                    <?php }
                } elseif ($paged >= ($max_page - ceil(($range / 2)))) {
                    for ($i = $max_page - $range; $i <= $max_page; $i++) { ?>
                        <li class="paging-link">
                            <a href="<?php echo get_pagenum_link($i); ?> " <?php if ($i == $paged) { ?>class="current" <?php } ?>>
                                <?php echo $i; ?>
                            </a>
                        </li>
                    <?php }
                } elseif ($paged >= $range && $paged < ($max_page - ceil(($range / 2)))) {
                    for ($i = ($paged - ceil($range / 2)); $i <= ($paged + ceil(($range / 2))); $i++) { ?>
                        <li class="paging-link">
                            <a href="<?php echo get_pagenum_link($i); ?> " <?php if ($i == $paged) { ?>class="current" <?php } ?>>
                                <?php echo $i; ?>
                            </a>
                        </li>
                    <?php }
                }
            } else {
                for ($i = 1; $i <= $max_page; $i++) { ?>
                    <li class="paging-link">
                        <a href="<?php echo get_pagenum_link($i); ?> " <?php if ($i == $paged) { ?>class="current" <?php } ?>>
                            <?php echo $i; ?>
                        </a>
                    </li>
                <?php }
            }

            if (get_next_posts_link()) {
                ?>
                <li class="paging-link paging-next">
                    <?php next_posts_link(' '); ?>
                </li>
                <?php
            } else { ?>
                <li class="paging-link paging-next">
                    <a href="javascript:;"></a>
                </li>
            <?php }
            ?>
        </ul>
        <?php
    }
}
//  <li class="paging-link paging-maxpage"><span>共$max_page;页</span></li>
Prev
End
没有数据