本帖最後由 pootor 於 2013-5-19 20:16 編輯
! U; ^/ B) H+ L) m" [luguokankan 發表於 2013-5-19 20:00 
& a' C. `8 J* A你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。, ]( N5 E; J/ A" }0 M8 c9 M- H
0 u9 f/ u7 p9 c" _
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php& u6 A% y. L2 J8 b/ S$ N. y9 t$ y
- $order = "&order=DESC";
?7 U) z3 ?; q! ~9 [ - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
8 g2 y' G j0 b, p* a - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }. G: p. d3 S Y S- z# X+ r: t9 S
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
, m6 L1 |* Z8 |8 ? - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
, c5 M {2 F5 l: ?/ a5 W4 q - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }6 ]9 T0 f7 J, b6 B! q
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
' S) i3 F! h; ?- q! t5 | - ?>: c, v$ D \/ U) R2 m9 O
- , U: V$ B, s' ~( X. P
- 9 @1 c* k2 m/ t4 f5 f% J0 P
- <form method="post" id="order">+ B: F7 ~/ E. S; U' z5 [
- Sort reviews by:9 F o* H* h5 i
- <select name="select" onchange='this.form.submit()'>
& H. q7 k- P. G- }0 W - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>& v7 x1 j, l+ k5 f& c0 p' B6 r
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>" W9 J/ K& r# n7 x: J. U7 S4 c* }
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
- J8 e1 P# w# P" X3 ~1 A7 d - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>" j q }8 l; M
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>9 J, i$ M+ w( Q4 g$ y
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>1 X4 E' v0 u* R) {5 @
- </select>. ~* o# @* _" r: m+ X
- </form>
; S" ~2 U% [; v3 \( t5 f - 3 [! M! }8 ]' } R' n& v$ n6 U
- <?php query_posts($query_string . $order); ?>
. f5 z2 ~1 V" {# s4 v - <?php if ( have_posts() ) : ?>* G5 V2 Q2 U1 A3 t
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |