本帖最後由 pootor 於 2013-5-19 20:16 編輯 5 n, y2 }3 P5 i+ u' q" X: ]
luguokankan 發表於 2013-5-19 20:00 
3 L5 F, f) ?% T- A" K. C( v5 Y你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
- Z( Q' [6 [" J; D7 B9 C9 u# \* |& A0 l2 H/ a
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php% ? p1 ]) ^6 l- D
- $order = "&order=DESC";
1 t& r1 @7 u1 t1 p - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }$ j1 K1 a4 ?7 s5 [" q" j
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }# W: {$ B" v( s
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }: c6 r* M0 u: Z9 w6 e: f4 g
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
2 } A% p7 a& R1 ^6 A/ v! \: Q9 { - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
* X7 j4 |- [# u/ B/ Y' ?* {. g - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }( j$ s5 i- y7 B5 G* d2 l' G
- ?>
4 y6 ^% ?, O9 Y. K
7 U( A4 E: v6 v6 y5 l
+ o' k7 b) L' Y; T$ G- <form method="post" id="order">
7 G1 B: h- T8 g# t - Sort reviews by:, l1 s. g; w, v+ A; _6 x
- <select name="select" onchange='this.form.submit()'>
: ~* z G/ G* P# C6 M- ]- {+ Z - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>8 e$ N; [8 @) F3 l: o9 J
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
q9 f" |( w: H) \/ g. q# u! P+ Y - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>* _5 _' C' k; k& P# x; x8 H+ W
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
: Y) M+ q. A) | - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
& w1 C2 d, B6 `, ]5 y - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>0 f- b2 @9 Z5 N/ k$ l
- </select>8 t+ u7 L/ h" I: ?% J0 w* y8 r# H
- </form>
3 o0 O4 v4 a4 T* J8 D9 I, e - Z& H# {; P3 J& B
- <?php query_posts($query_string . $order); ?>
* I8 z- \3 q" p- J5 k" E2 c5 I9 A - <?php if ( have_posts() ) : ?>4 K' f" O* u, u+ ?: d
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |