本帖最後由 pootor 於 2013-5-19 20:16 編輯
8 E3 @2 ^, v, N$ v, L* y* n$ tluguokankan 發表於 2013-5-19 20:00 
5 ?2 S# w8 D8 a' C9 O" k: c4 A; N你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
, ]* t$ R1 m0 P9 H" H7 I( A- i5 \1 b J, A) m& t' e9 U. @9 F4 Q
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php' Q+ {3 X1 J: R7 ]6 x% n
- $order = "&order=DESC";
7 `( y; C2 V/ k m: T - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
" k+ k) |; q8 s) f6 ~( w - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
3 }$ C% a# n/ g8 ^" b, \ - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }4 h( m% t* ~0 g+ G% S3 C1 Q
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
( K5 c; O1 P6 |1 ~ h - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }& H2 r7 W; O& G$ w9 V
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
$ O0 }3 h( O3 ^ A o5 b1 I, K - ?>6 j* t5 S1 r6 h8 A
9 j- h, ?$ K, A0 H! d7 D( J" \
6 j/ i( _7 M, x- Y- <form method="post" id="order">$ Z H" k9 a, x5 w3 v
- Sort reviews by:( {+ A( ^8 k% y& d
- <select name="select" onchange='this.form.submit()'>
* ]6 E2 k2 p1 [2 ?4 m9 p - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
x$ ]0 [; R- C" s: W5 A1 Y$ O# L - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>7 r8 k a1 g+ s) s* P* V8 e
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
4 q! i0 [! I. Y- ~ - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
5 ?, p! b6 X; k# _' f" x9 X/ D - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>7 o- U/ i3 ], i& x+ h* I* V9 q
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>8 {9 F& b1 h; r
- </select>
, _. E; B6 ?, j" D7 O7 l - </form>2 ^! e2 _7 y1 d
- ' v0 N5 U9 S) B5 b& Q% q, I5 a* x
- <?php query_posts($query_string . $order); ?>+ D5 k% m( `0 E
- <?php if ( have_posts() ) : ?>
" G" L7 b& [, Z# K, S/ u - <?php while (have_posts()) : the_post(); ?>
複製代碼 |