本帖最後由 pootor 於 2013-5-19 20:16 編輯 9 @1 }; D. n; u) N% G q; J: K
luguokankan 發表於 2013-5-19 20:00 
3 j2 r' _6 S. J$ V3 Z- ^8 l+ H O你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
+ _! A# E& I. l5 C0 S$ L
3 g, f) h, i% y6 g* A P* \不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php) ~5 W0 \6 E6 @5 s/ ^
- $order = "&order=DESC";
# V" c$ H* R# F, ]4 z5 S( q! S - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
; A! i/ N! p+ ]4 M; r2 @ - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }& p) k: ^8 M; O, O) a
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
' d% Q5 X$ K4 X# H, T% c& C - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
% _1 s* _' C( K$ \, f! r - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
0 p. F+ l |9 \2 b2 B - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
+ J1 s: f4 Y0 t6 c/ l5 o& {# f - ?>/ Z% E* h7 X; f7 Z) S
9 g) z4 H& r7 E& {4 s( _
( t+ T8 L6 u: L! U/ |- <form method="post" id="order">
9 Y% E5 ^ ^5 f* B - Sort reviews by: r2 C9 O. w7 h+ S/ L2 x' Y! P5 W G
- <select name="select" onchange='this.form.submit()'>: }9 t! n8 ~- y$ J, T# ~8 k
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
# C& m! ~6 W; w5 c% O- Q4 B - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
7 e! K# L+ y% p8 D6 B7 O$ A - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>- z8 _& `% M# d8 C r6 i2 `
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
: h( a0 Z# X3 T6 g% l - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
4 l. `& q' T9 Q" j* z) H) f - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option># @+ e( L7 Q( r" B5 X+ F
- </select>
* l& P3 G/ r3 \$ m' L - </form>
2 `9 q& F' x8 ]4 E; d - A3 y0 V* ], E7 |# F6 e
- <?php query_posts($query_string . $order); ?>
3 O3 I6 `% g( B$ c1 N8 f - <?php if ( have_posts() ) : ?>
7 z. Q* d, r* R0 w- x. Q4 q2 I4 g$ O - <?php while (have_posts()) : the_post(); ?>
複製代碼 |