本帖最後由 pootor 於 2013-5-19 20:16 編輯 5 Y5 \* S: o. _( ~
luguokankan 發表於 2013-5-19 20:00 
+ A( h( C( H" b1 P* [9 S9 r你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。; z; G6 n8 r" O, `& X2 Q9 T. \
# ~7 y$ S, }" W7 z) C- i# E2 V
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
: v* x* D6 ]5 D. ]0 C+ O - $order = "&order=DESC";3 X$ F, ^# C- |1 E7 _
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
8 h* A x) n5 ^8 {+ [7 i7 V( e3 ?& ^ - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }! ^: W5 Q) L% ^% ]- c
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }: ~5 x+ Y9 ~! V
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
o+ N+ O; ?4 j2 F0 y. W/ i& M2 b - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }+ s, |9 W8 c' j7 I' O) V3 L' s4 b
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
* J- ?* U v0 E8 L0 K) Q! c - ?>: c5 K2 R0 b) I1 Z/ i8 u2 E
- 2 h! @+ [+ |( r7 _
6 l# K7 v4 f, u5 {0 n/ f: E' r- <form method="post" id="order">; K% d+ p) g. Q
- Sort reviews by:
& d" n# Z8 |2 J. C6 p - <select name="select" onchange='this.form.submit()'>8 s' f/ x9 p& \- Z, U
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option># o( @0 S' a/ ^* y
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>& A3 _# U9 _* } }( z! [5 V
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
2 R! G4 i X6 x" K - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
5 b v$ s2 `( ^" ?& d1 X) t - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
5 L4 R' K6 o9 f) U7 K - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
/ c% j. c% F8 x8 ~3 ~& c# {/ Y. ` - </select>
7 }/ Y& n9 b9 B0 {1 D7 G; f) y - </form>
9 @1 b" ~' s1 s" i6 q - 9 ]3 [# Z* y) l3 E
- <?php query_posts($query_string . $order); ?>1 Y* g' g- D, x {, r
- <?php if ( have_posts() ) : ?>
! z! H7 R5 [+ X. S* z2 K5 {, E3 ^9 O - <?php while (have_posts()) : the_post(); ?>
複製代碼 |