wordpress如何自定义分页

以留言的分页为例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
define('DEFAULT_COMMENTS_PER_PAGE',5);

$id=get_the_ID();

$page = (get_query_var('page')) ? get_query_var('page') : 1;;

//$page=2;

$limit = DEFAULT_COMMENTS_PER_PAGE;

$offset = ($page * $limit) - $limit;

$param = array(

'status'=>'approve',

'offset'=>$offset,

'post_id'=>$id,

'number'=>$limit,

);
$total_comments = get_comments(array('orderby' => 'post_date' ,

'order' => 'DESC',

'post_id'=>$id,

'status' => 'approve',

'parent'=>0));

$pages = ceil(count($total_comments)/DEFAULT_COMMENTS_PER_PAGE);
$comments = get_comments($param );
?>
<?php foreach($comments as $comment):?>
<li id="comment-<?php echo $comment->comment_ID?>" >
<div class="comment-author" >

<?php echo $comment->comment_author?>

<div class="floor"><?php echo $comment->comment_date?></div>
</div>
<div class="comment-body comment even thread-even depth-1">
<div class="comment-description">
<?php echo $comment->comment_content; ?></div>
<div class="clear"></div>
<span class="datetime"><?php echo $comment->comment_date?></span>
</div>
</li>
<?php endforeach; ?>
</ul>

<?php

$args = array(

'base' => @add_query_arg('page','%#%'),

'format' => '?page=%#%',

'total' => $pages,

'current' => $page,

'show_all' => False,

'end_size' => 1,

'mid_size' => 2,

'prev_next' => True,

'prev_text' => __('Previous'),

'next_text' => __('Next'),

'type' => 'plain');

// ECHO THE PAGENATION

echo paginate_links( $args );

?>

 

坚持原创技术分享,您的支持将鼓励我继续创作!