本帖最後由 pootor 於 2013-5-19 20:16 編輯
" v, z1 b: M! G$ D- lluguokankan 發表於 2013-5-19 20:00 ) k. D% h, A3 A0 B3 b1 c! l0 R
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
" |) ^2 y8 _) Z9 F; P% ~# y( ]0 _) T; ^( @$ W4 T3 _0 G; u
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php {' I V; z: A) m9 z8 n
- $order = "&order=DESC";4 I7 W6 j) J6 G5 R9 C
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }4 n& Z+ K. u. a) ~' c: O6 f
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }+ W) x5 j% W; P8 e1 K: h. V; ?1 g
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }! i6 m% K; A0 e( q. q
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }0 Z4 P" v' G) P8 G7 h0 c! i
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
& m) Q) ? K- n4 q T7 H( `; D# ` - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }. k& |! J/ K v2 P! @' P8 n8 k, t
- ?>
5 M$ J# w* c/ [/ w( Y7 j1 P
/ @/ q8 T- c m6 Y- + ~& A# g- G% \7 G z2 D0 z9 T. `
- <form method="post" id="order">) _) j5 p2 p/ b0 G6 F
- Sort reviews by:4 v0 i+ J" i) s
- <select name="select" onchange='this.form.submit()'>
: u. r X( o7 z4 e9 n3 F. u - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
0 g3 [7 I5 }. l( {5 Q! h - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
7 j" U1 v/ z5 h. c8 u; \8 z: Q - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>% Q% B/ _& r& n. b# {
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
$ h6 J+ |8 t; r7 O, W% z( E - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>* H' J4 h! {" L* j2 ~6 m# ~
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>- R( U5 q8 H2 t6 K, l7 x& l* E
- </select>9 s1 k6 m( S9 _) j* D
- </form>
/ W, V" @3 B8 T- T) U' F
3 V; V6 X3 G+ i- <?php query_posts($query_string . $order); ?>
3 ` D4 w6 [+ {7 Z, w% z - <?php if ( have_posts() ) : ?>
& ]* G9 d1 P8 \: |, B3 W4 A* [% q - <?php while (have_posts()) : the_post(); ?>
複製代碼 |