本帖最後由 pootor 於 2013-5-19 20:16 編輯 # Z7 Y2 w1 |4 c
luguokankan 發表於 2013-5-19 20:00 , E7 m% a; ^7 g5 }
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
+ {+ f1 K( Q( w2 D+ N* h7 O7 M9 d/ E. ?$ n
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php8 }9 c* p3 L/ Y; E! V) ?* _9 q
- $order = "&order=DESC";
# ]) F0 a) p: T - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }' Y! L* J$ K7 v7 e' |
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
8 ?7 X2 h7 I: k( Q - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
* ~6 `- O6 k* t- l" d* Z - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
( u% d D: }5 ~# J; C* N - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
# b$ Q; X: V' ]6 B9 B - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
. I/ a$ ]' w1 [3 | - ?>
, P1 V c8 `* C! [
) ~5 ~# ^- C) F6 z. |6 Q
! F2 P+ i) [5 J4 E# r2 `6 P- <form method="post" id="order">4 G8 }$ m _# e4 N; y
- Sort reviews by:2 ^/ t( ~1 w3 ]" Y, h+ r; S
- <select name="select" onchange='this.form.submit()'>
, S# M, P! I; g3 j - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>6 q+ {: T% K" n6 F( b+ O
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>: D# I; ?+ l0 X3 m! V
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>) ~! w3 l! h4 \( X
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
8 n& b6 l* } ^+ G5 z - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>) a m0 h* O6 z' I" |
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>4 \& J; o1 n: @4 L
- </select>
: ^. ~# w0 [$ F% c. b - </form>
/ B# i t) Y6 Y8 ?) C9 q - " V' c( ?7 s. G& N) X) j7 l# e
- <?php query_posts($query_string . $order); ?>
, X3 S* ^$ @. a# ^ [3 x - <?php if ( have_posts() ) : ?># i$ _) f! D3 W, r7 J. Z7 ~
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |