本帖最後由 pootor 於 2013-5-19 20:16 編輯 " I4 G" L. P8 m( D
luguokankan 發表於 2013-5-19 20:00 / H- m. b% e( a x
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。8 j r. |" y3 l3 W
, h; E, t* M# i不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php5 I" z- F/ `3 A6 V; ]
- $order = "&order=DESC";" e) @4 ]$ |, w& a
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }5 `* n; P' I* z* l7 o# o( N
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
4 s8 z5 k4 p. l) d' I - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
* u7 Y' g% d/ R3 `4 e - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
5 j# W! ^5 e6 S ~* q' T% K - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }% @/ P- o! ^" i" V5 Z: h w8 _8 I
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }( I1 F/ J6 y) r! w# }
- ?>
6 d" W% |$ I: j6 ~ - 8 V9 Q5 C. |3 g9 |) R) s* Y0 z
- 0 z; [& c9 L& j; R; z2 u4 X$ ^7 B8 _; Y
- <form method="post" id="order">
0 k! B. ~& ^1 p" e, T# Z( |8 K - Sort reviews by:5 l2 D% Y m' i" X7 C# ^
- <select name="select" onchange='this.form.submit()'>1 w, A/ T [0 R J' t1 i/ }
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
( w1 o3 y9 A1 S$ h: L4 H% \6 e. M - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
2 b: o. a v* o+ I2 P - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>3 x: r3 T5 D& V1 d, D
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>1 _1 y( A/ n# i( m$ t2 F9 S! X
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
, k$ n$ R" E0 g8 n1 v& H. f - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
9 a$ e2 {! V* O2 G( u5 d! Q4 ] - </select># i) f- r ~( s4 T
- </form>7 C& G/ X* s8 N, C! A F
% ^- r; E6 I$ `- <?php query_posts($query_string . $order); ?>$ X" u. V) L$ \& G
- <?php if ( have_posts() ) : ?>& Q) d- k0 z) h
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |