本帖最後由 pootor 於 2013-5-19 20:16 編輯 ' T/ @/ Q* G8 d& W* f( N
luguokankan 發表於 2013-5-19 20:00 
" C/ M3 ]% G( C( q' m你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
4 |: k6 z; l+ A0 l/ \+ g
& J& p _- C2 M9 l不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php9 a# ~8 J! Q5 E! H$ K& x
- $order = "&order=DESC";' c3 J/ C; n8 D7 k
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }3 y9 b% U* O1 y) q" t
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; } y$ n% V, {1 W! K3 D7 M
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
' e# B' m8 y3 H3 I0 V - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
- o7 Y" |3 }* e& } - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
+ p, Y7 B6 o5 D, \5 g/ n0 E - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
5 V; k: Q( V3 H o - ?>: ~* ] p+ c# m1 q& }; k3 c- Y
" a/ W# t- W0 d1 s4 \% j- , ?9 d4 u: B* _! J% ^
- <form method="post" id="order">
$ w3 n! t8 M2 f4 a - Sort reviews by:. A/ B' D& {# h' {9 B6 m# @1 `
- <select name="select" onchange='this.form.submit()'>
, @! ~1 L& l$ l$ B7 H9 n - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
, n7 M; X" n+ X1 |* g8 p - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
4 K z& X' y5 M/ Y - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
W7 @. @$ J5 q - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
; s1 L! h! c" c( S3 v l - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
1 E9 D& {+ y9 r# C4 K# h - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>9 M5 ^/ c7 w6 W* R0 l5 g& H
- </select>
) I, f3 y; |1 P2 ~: r - </form>
6 w- e4 N: b+ f% F& ^) Y
* d; p+ H; y/ D; H7 V+ T x' ~- <?php query_posts($query_string . $order); ?>: X# z7 H+ O4 H. n, V( G# X
- <?php if ( have_posts() ) : ?>
& {1 l N9 Q& Y1 ^% u& h - <?php while (have_posts()) : the_post(); ?>
複製代碼 |