本帖最後由 pootor 於 2013-5-19 20:16 編輯 * q9 R( w: v3 r$ m8 d
luguokankan 發表於 2013-5-19 20:00 
5 I/ u2 q9 I3 M, @4 c, S你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
) X6 C1 L: G" X* S Z
& r, f& Q! t8 [9 Z不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php$ ?! N0 J" M3 O4 `
- $order = "&order=DESC";0 `0 g+ W0 n% B1 A
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }/ s2 ~, S0 E7 B/ h# l. i+ I
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }/ s, w" c+ u2 z1 C
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }3 ]; I% } w! l; U, n) O. C7 ^
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }5 k7 m6 f& c- h! e2 Z: x
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }/ e& x/ h: s, U
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
" x3 _3 x- T" [: D, W% n+ ~ - ?>% L, @( P, I# ]( g- o
- 4 c9 H' G( a1 ?: i. `
- 7 D, |! {! ^) ?6 ?6 a; n# P
- <form method="post" id="order">: @/ Q: l6 x8 K8 I4 G5 I2 ]; B
- Sort reviews by:
2 E b7 t1 Q% r. E - <select name="select" onchange='this.form.submit()'>
* b# k4 `; c, {3 h$ e - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
$ t/ L' V* |% B4 x$ ? ^ - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
9 V" N1 j+ o! I1 h+ c+ O - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>! a; v7 U6 i9 I8 z7 D! q4 U5 Z
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>$ x1 a0 a$ T) Z0 D9 V) I" S
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
+ Q8 e$ y& ^" M5 i5 g6 g' }( V - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>0 E2 B9 ]' O! q3 z
- </select>
& X+ Y# n- ^# k& j4 Z/ C% c0 q; I - </form>
2 N; j3 K) B3 R/ y- M
, N8 ]; p* }7 ]! }- <?php query_posts($query_string . $order); ?>
6 P) N! V9 f' r% O! j9 ^ - <?php if ( have_posts() ) : ?>: J0 T! m0 L3 M% h- j
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |