本帖最後由 pootor 於 2013-5-19 20:16 編輯
3 X" H* o8 q" Sluguokankan 發表於 2013-5-19 20:00 
, {; C6 }, L! s4 d+ W$ `& z! c你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
# q7 g8 v v' ^% k7 s) c; @+ r: y6 n2 {
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php. a6 i( [ U' u2 b2 j+ w! G. x
- $order = "&order=DESC";
) Y2 x/ M& [2 L' c/ M - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
* z; m$ B7 X/ L5 _( Q, l - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }/ U6 g( W& [7 ]+ d' D! k- w
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
# W* r) d7 |' Z/ b - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }! b3 _6 Y/ U- ]
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }9 j; H4 Z: ]" G& m& }6 \ x, c
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
+ _- m7 p- o7 u) m - ?>
# [7 `' b' X ^* W& y* R" }/ D - % E: L; F6 Q/ ~5 x" ? `
. b6 X0 R9 b, G- <form method="post" id="order">
. |( V9 ]0 I0 O - Sort reviews by:
0 o( \$ o5 H" C- y7 u, y - <select name="select" onchange='this.form.submit()'>
. Q2 W" z1 d* N - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
6 J- ?' l5 \" E* X0 e1 ^4 E - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>( d. t! S/ l) F( s
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
0 u# @" }% |3 h/ Q - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>+ d% I. J5 m9 M
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option> n6 {* ~! j9 L4 w2 X- o) D" M( S2 y
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
! w8 G! t3 V5 S& U - </select>4 Y$ N' T$ e- @) V
- </form>3 Z2 W: o+ G; h' ^
2 D7 F5 l7 |# \" w3 q! m+ h- <?php query_posts($query_string . $order); ?>
: x4 M. a6 v% O& A8 ]0 g# Y - <?php if ( have_posts() ) : ?>! L2 J$ l# u, [
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |