本帖最後由 pootor 於 2013-5-19 20:16 編輯 3 Q* s }7 F2 K8 ~( ?# a( S2 p, q9 C
luguokankan 發表於 2013-5-19 20:00 
/ I( l x9 O! L. v5 ?1 [你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。% L% b8 M! |$ [3 H& v
9 V% c# K' M/ y不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php) q3 P( S8 Q4 p) A
- $order = "&order=DESC";
2 P- w4 T( \" P8 o6 H p - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
$ g" ^, v6 Z" ?( @9 `. V C5 a - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }; p. d4 n, P; t
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }. ]' q5 M9 M" Q* D. F# ]- R- F+ k5 ?
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }5 H& p' Q# [0 U, c6 E4 s
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }2 {3 c) Q3 R6 W% ^% f
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
( I3 s$ v( t3 t) n; T - ?>
' M& H$ B5 [5 E8 a" @% t - 8 g4 B) L" |5 _
- 4 {* n' }& W3 J, y$ L( S
- <form method="post" id="order">3 f# W& X0 t- d/ E j( j
- Sort reviews by:8 d" D$ r. T! o m# W8 |
- <select name="select" onchange='this.form.submit()'>
$ G- i1 C! f7 _! M, I: @, j6 V - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
+ z& [* T. {( y$ A. {8 } - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
- H" n! _* m; S' x7 s - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
* c. a# h7 g2 G2 F - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>2 _( u# h2 z) D: g; p
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
5 f; W( M+ g- A0 R# {1 K, K; T - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
# g* m! w2 t0 p/ [ - </select>! U2 |1 \) \6 [# C
- </form>$ h9 A1 Y9 w% R
+ o: Q1 _9 M: j* U. H8 s& j- ^- <?php query_posts($query_string . $order); ?>' g. ~; N% k: z/ |4 L
- <?php if ( have_posts() ) : ?>- @# L8 X; E K) t
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |