本帖最後由 pootor 於 2013-5-19 20:16 編輯 4 `7 u, v1 `3 u: ]: M9 p- w
luguokankan 發表於 2013-5-19 20:00 ; k; `5 X! |- B Q
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。( W! E, |% \4 H9 M
( h) G ^; I5 N0 q; W2 u不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php2 y6 s1 |/ h9 `
- $order = "&order=DESC";) a% e3 t! w, p2 h. q1 }
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }1 o1 |5 b4 R8 C7 o( s* i
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
8 I% N+ @% y, [; o9 ^ - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
4 B1 K9 s7 T0 O - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
6 m6 C, R( V8 ^6 H" o; y - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
$ G5 K+ r" c6 `8 \% B8 W0 Z - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
! {8 N, U" M3 L! @7 _3 { - ?>) a- G) v# W0 {
- & u* ^2 }. o% X7 |) y0 Z1 r* X( |
7 J: R6 m& X/ k5 \- <form method="post" id="order">
) D" [. m6 P8 P6 V4 X% C; a2 R5 E - Sort reviews by:
, l7 l/ l1 O! W9 F2 |7 N# U9 _% f - <select name="select" onchange='this.form.submit()'>5 C2 ^- ~5 m. c) r
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>, t; e3 D ?4 R3 d- B% s
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>4 z* m7 a* X$ B: B4 t
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
/ B0 g: a9 l: g3 ^ - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>$ L* N8 O* q. A) y0 Q- ]) j
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
+ C% V1 P- M6 M" a5 _0 b - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
( m; w6 v& x& e) ~& ?% n& N- h - </select>
+ W, g% |) G, y/ W - </form>; o# e0 J5 P$ d2 S i& @3 B
- 8 G- @) F5 Q* ]1 r# N) [4 z9 n$ X
- <?php query_posts($query_string . $order); ?>- Z g4 ]; z4 k( U1 \
- <?php if ( have_posts() ) : ?>( |4 P9 |/ ?# L8 l
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |