本帖最後由 pootor 於 2013-5-19 20:16 編輯
& k* R& x/ N- Xluguokankan 發表於 2013-5-19 20:00 
1 a- I) N0 d) v4 I你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。8 Z& U2 l! {1 p1 ^) a
' B# R- X2 W2 x! L; G% w
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
: F+ q* @" a4 g5 P% ? - $order = "&order=DESC";
: ^$ W ?/ m2 t - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
! n& s3 c' b( @1 J! B0 [ - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
2 P9 y% a1 a6 H4 T- R) K6 ` - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
. k* O- M/ z, ?2 ~ - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
3 o( O) ~+ X# K; m - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }3 o# l" l4 k3 y/ |' Q/ _4 @
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }/ [9 e3 b& I0 {' U3 Y7 d
- ?>
7 o6 ^% T. ]9 j/ w+ X( p - + t. m( O. u3 u" x* @& q
+ @5 b$ A& { {8 k2 |3 `& f' r; A- <form method="post" id="order">8 Q$ a0 h, N8 B
- Sort reviews by:
1 m8 q3 c9 b/ l' K$ u - <select name="select" onchange='this.form.submit()'>2 D; G; v! N, H6 e( |) L% j
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>2 o" Y: t# _9 n' ` s
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
, ^% n, _0 [6 ]3 f4 c9 C+ Y - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
+ W. D5 A7 Y) S' | - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
( ?- D# f# J$ g/ M/ H - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>& k: t- T! _+ v/ k3 n+ p3 h
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>. Z& {0 x" z6 X: U' i7 @; w
- </select> M* u5 h; |% N
- </form>; K. k1 S) ^- D: H" @ V, x; w
- # b0 K$ _7 `7 M# W4 F* k
- <?php query_posts($query_string . $order); ?>
6 c" u& s' M" q) I) ?9 T - <?php if ( have_posts() ) : ?>
3 K* M/ B8 o/ @ - <?php while (have_posts()) : the_post(); ?>
複製代碼 |