本帖最後由 pootor 於 2013-5-19 20:16 編輯 ( Z7 Q) z$ q- ^; [
luguokankan 發表於 2013-5-19 20:00 
- E4 ?' }. E3 L9 \/ A6 O+ E# s你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。5 ?0 K0 H1 p0 O, S7 M% J/ x
$ ?- Q0 g2 }) ~; j x' D6 V, t
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php( G6 O. @& Q/ |0 r( z1 C) h& D' v( N
- $order = "&order=DESC";0 j7 d0 I6 R- M7 Z
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
& ]( K9 X1 ?5 t4 A - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }" M: u& [9 Y ^2 ~8 t
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }! L% {% f! I0 w/ r6 {
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }& _2 u! z) n2 ^. A2 D
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
( ]8 Y- u# Q- P8 e - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
- T- {# m% w$ m# N6 d Y - ?>
3 c; Q4 }' c0 U6 D/ r
' h2 N: C& W) z2 B& j
3 p0 p. } _1 | [- N2 O7 {- <form method="post" id="order">
: l, `7 }7 A$ V* z4 y1 f m; V - Sort reviews by:
# M1 X5 d( K1 G# j* c1 m - <select name="select" onchange='this.form.submit()'>; R8 h0 _+ j5 c
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
% n9 W& ^4 u* r! H8 N. z - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>, d: I! H/ v2 e& W! S- T
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>/ ~: N' J, c) n( }
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>+ I3 Y7 v4 N! p- U9 k$ |" K$ B6 {
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>- Y) c- p$ a' R: V- B
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
0 F: {/ J0 Q) z m( k; q - </select>
9 s1 H z* k5 i - </form>% T9 ^4 o) T! O% d) h
& N! H! h/ o u; Y0 d9 b/ m% Z- <?php query_posts($query_string . $order); ?>
1 D8 G" D+ G; ]$ b - <?php if ( have_posts() ) : ?>
% t) ~. p" |' u6 K- @ - <?php while (have_posts()) : the_post(); ?>
複製代碼 |