<?php
/*
Template Name: test1
*/
?>
<?php

get_header();
do_action( 'ample_blog_breadcrumb_type' );
?>

    <head>
        <title>网站收藏</title>
    </head>
<!--//内容-->
    <div class="col-md-8 content-wrap" id="primary">
        <table class="table-hover ">
            <tr class="active">
                <td class="td">ID</td>
                <td class="td">网站</td>
                <td class="td">网址</td>
                <td class="td">简介</td>
            </tr>
            <?php
            $total = $wpdb->get_var("select count(*) from wp_collection");
            $comments_per_page = 3;
            $page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
            $nowPage = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
            $offset = ($nowPage-1)*$comments_per_page;
            $results = $wpdb->get_results("select * from wp_collection  ORDER BY id limit  $offset , $comments_per_page");
            foreach ($results as $result) {
             ?>
                <tr class="success">
                    <td class="td"><?php echo $result->id ?></td>
                    <td class="td"><?php echo $result->site_name ?></td>
                    <td class="td"><a href="<?php echo $result->url ?>" target="_blank"><?php echo $result->url ?></a></td>
                    <td class="td"><?php echo $result->jianjie ?></td>
                </tr>

            <?php } ?>

        </table>
        <div class="pager">
            <?php
            echo paginate_links( array(
                'base' => add_query_arg( 'cpage', '%#%' ),
                'format' => '',
                'prev_text' => __('上一页;'),
                'next_text' => __('下一页;'),
                'total' => ceil($total / $comments_per_page),
                'current' => $page
            ));
            ?>
        </div>
    </div>

<!--//右侧-->
    <div class="col-md-4 sidebar-wrap" id="secondary">
        <?php get_sidebar(); ?>
    </div>
<!--//页脚-->
<?php
get_footer();
?>

分页函数: https://www.boke8.net/wordpress-paginate_links.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据