本帖最後由 pootor 於 2013-5-19 20:16 編輯 7 u; g1 d1 q1 z" P. @! z, L" V
luguokankan 發表於 2013-5-19 20:00 
! e- v2 F5 ?' L* v8 p: U. U. n P你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
% l6 O. X- [5 |. M
1 [% s0 @5 p: s4 e不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
" i7 L( p/ ~( V8 j9 R7 e! J - $order = "&order=DESC";
8 F6 z3 v6 }3 D0 N! V9 B% M - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }1 ~. e6 L3 Q: L0 j( i! [
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }9 g3 Z2 r2 Z1 L* e+ Z" Z9 P
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }6 T+ s- }; @1 }6 S ~3 C, M2 ~
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
9 y9 `" u1 j# J5 V. F* Y# S - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }9 _* `+ f" {* E5 z
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
5 @* ^* {" W4 }) ~& N - ?>
0 H1 B$ L& }! |' ~0 q+ N
3 d/ B* c$ r/ B6 I: L+ X
# g, w2 V' M4 d, }" n) O/ I T- <form method="post" id="order">
7 ~4 }8 x4 o' k& c - Sort reviews by:
/ x$ u' u. y2 |* I. ]5 G. f - <select name="select" onchange='this.form.submit()'>& ]! \2 w0 x. R! {& w" I6 b
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>' |1 A) V3 h/ v& M" \1 R. s3 t
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>9 C( v* u0 [0 n, ~2 S* t
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
* |1 n: {0 n( [ - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
. _& q6 `( I% [. f - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>0 l8 }7 i* U* }0 `& U
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
/ ^. C) ?" a( J5 c( E+ d# x - </select>' }7 Q" J( M8 u- _9 n$ I; X
- </form>; w3 o9 y2 g4 U* `& b8 @8 |# F( Y9 b
- % m9 Y' b/ E0 p, W8 h' r1 z0 v
- <?php query_posts($query_string . $order); ?>
, z' J' p* p: M- `$ t - <?php if ( have_posts() ) : ?>
7 V" x. _1 D6 n& X6 h% A - <?php while (have_posts()) : the_post(); ?>
複製代碼 |