本帖最後由 pootor 於 2013-5-19 20:16 編輯 $ p7 l% K) f9 n9 N
luguokankan 發表於 2013-5-19 20:00 2 K+ I9 C1 c+ v
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
8 X: k! U4 _& Y% B
) ]" F' f' |7 x$ y不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
6 E- d0 O0 z6 i/ A2 Z - $order = "&order=DESC";! Q& ~. L. W4 ~
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }6 F5 n( p6 d7 j/ f% D0 u
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
0 Z1 r- }! }. x' j' S - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }/ X2 s0 l0 M8 D/ l3 I+ j5 v% ^
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }) |, u& j& t5 B# w
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
2 X% D/ S5 i% H0 T( d5 E - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
+ |4 j5 s; S# p! ? - ?>
. @* }5 L! P4 E8 s, g - 9 M! j' W9 L- q; x8 U3 H1 j
6 p" Y8 j( B; X* ]1 @& G- <form method="post" id="order">
7 F5 g" X/ r3 [6 V# N5 X - Sort reviews by:
2 k1 Z: [/ U X8 l$ Z; m - <select name="select" onchange='this.form.submit()'>
3 }# r, Q& [, ^! |8 l% z' e - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
1 ~5 f9 O: j* M. X, v4 k1 Z - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
& R8 Q& A! \1 Z" E$ F8 h8 e - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
0 G% m* Z! @1 ^+ d# a& w L - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>* c; s- F3 ]/ ` ~, I5 {' B& @
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>8 w9 c$ J: t0 l$ H6 o) f
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>. g. m" s0 A- y3 K5 T1 a
- </select>
: j, T, @/ R) i) Z6 L - </form>
1 h! Y- {' y5 g3 ~4 v5 V# F - p/ X! U2 W0 B( X" f. v% P" b. m
- <?php query_posts($query_string . $order); ?>
% ~, ~$ j q/ q0 p2 r - <?php if ( have_posts() ) : ?>
' c# C: q$ ^) H0 @9 T: I5 M - <?php while (have_posts()) : the_post(); ?>
複製代碼 |