本帖最後由 pootor 於 2013-5-19 20:16 編輯
( [% H0 L; O+ d3 uluguokankan 發表於 2013-5-19 20:00 - y) |$ `0 p. t% t, x# k' Q
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
* M5 x& \* Q1 j: ~2 X1 c5 O! {+ X3 y: }2 i8 ?& ], y \/ s
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php: c2 }7 F; D( W
- $order = "&order=DESC";
1 [0 g* p9 L1 i# g9 f5 d - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }0 Y1 A; E% O i+ D, I( \
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }. g6 U' n5 T7 `: C- C
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }' m: \- _! _$ h/ N
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }4 ~8 B% H1 F) L- Q
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
/ a% K: o' i O- p) i - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }7 P0 e9 J6 K, }
- ?>
7 n5 _$ x7 o Q4 \5 E2 c
- q, x$ p7 h6 r! i5 \; P4 i2 u- 8 L* F! J$ X! P W! E0 P
- <form method="post" id="order">4 G1 {: s l! A# f
- Sort reviews by:
7 K5 e, x( M/ n0 z" | - <select name="select" onchange='this.form.submit()'>' N9 a. o! H/ ~+ I8 h, f! S7 v; A
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
* w. A* f" l5 T2 C' f4 u$ b - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>1 A+ `( n1 ^2 E( ?9 P7 r
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option># h4 G5 G D- y
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>5 @! b T( D7 y+ y. g! S0 v" D
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
% H! o5 D5 J- v$ ^+ u( J- y - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>7 K$ V: t) U: _# H+ i( l. I
- </select>- t4 z+ ?1 L9 A* i( z2 I" ?2 T+ R
- </form>
2 X# a$ S3 I4 P9 q/ |1 c8 f
- B: a/ o( A7 [- <?php query_posts($query_string . $order); ?>5 `# ?8 Q! G4 \) }& v- ^
- <?php if ( have_posts() ) : ?>
* [3 i' n( ~1 T9 V - <?php while (have_posts()) : the_post(); ?>
複製代碼 |