本帖最後由 pootor 於 2013-5-19 20:16 編輯 ; r# k6 R& k. ~2 H: w/ t4 |
luguokankan 發表於 2013-5-19 20:00 
! t# [, X4 p+ K; p1 d你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
" x3 t1 q3 F; G `+ l- m8 W- W+ ] `! ~# |& R- A! U5 ~) v' D
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
0 C" b- w. D+ ?3 L - $order = "&order=DESC";
) V8 e1 t1 @* e5 J: B - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
2 D( N7 V% R$ O7 e$ C( C - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }6 V& u+ G! c2 j" s3 R: {& W' O* h
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
9 N! D, y1 j; M& ^3 u9 z; J - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
3 Z% C) j0 Q( v) S* D0 t* e - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }& l* ]& `: v; `1 k1 A4 W
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
M1 c! _: }3 R' g2 w - ?>
( f! w, _7 p# I% [/ a" K
* F9 `; a, v; l4 a$ Q4 }" O- 2 J# H" s7 B" s4 n4 l5 Z( ?
- <form method="post" id="order">/ K/ G2 e, E, m' }4 Y
- Sort reviews by:
7 _3 {; C3 t, n - <select name="select" onchange='this.form.submit()'>
) ?" @6 `' D, v+ C - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>9 d8 `' q2 t5 O0 T
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>3 w# d4 Y; D+ Q$ e/ A* K
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>, Z* ?# Y4 N" T- E7 K4 z
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>( i. s3 H+ \( t7 e$ f$ l- t" h
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
# _( l5 o: z3 p0 P" { - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
( A( G9 S, s5 w4 g0 h - </select>2 [- Z* ~4 u0 O ~1 c1 G: E
- </form>
. z/ C" Q3 P* c+ H3 R - 8 e% Z" O P- q( n) R' m7 G) D Z) k: g
- <?php query_posts($query_string . $order); ?>4 ~$ x: [: F$ g. a. s! J. W3 {. Q
- <?php if ( have_posts() ) : ?>
) e0 o0 M9 ~+ `" ~ - <?php while (have_posts()) : the_post(); ?>
複製代碼 |