本帖最後由 pootor 於 2013-5-19 20:16 編輯 " `' W" f; E$ H9 ]2 ?$ X
luguokankan 發表於 2013-5-19 20:00 
$ Z2 A1 {& o& Y! ]; z* ~: n9 E7 [) o$ ~8 R你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。- i: V) q0 S6 ]1 q& [5 |
1 s! b3 d/ ]8 w
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php# U. m H. d6 @- d4 b7 S7 I
- $order = "&order=DESC";, f: K; U% d; l& F& |( s" f
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
9 I* d. o- E2 k$ {( z# Y - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
% v8 U4 b: h' c |' y4 V) q; B9 R9 H - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }% q* b5 G& [3 e" X1 b
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }- v; i$ N$ g6 K% w. J* z
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }2 E' L7 Q0 \' ~2 s& J' ], N
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }- f! M. i- x5 r( k
- ?>! B$ C/ }% F: n; n7 }3 w
- 0 M; V# n7 Z/ u$ \. s6 o
- ) I3 E* ?' S/ _
- <form method="post" id="order">
2 R) m4 h. b' q z, y# S' W; ~( M - Sort reviews by:
" R, h9 y1 r! l- M8 D - <select name="select" onchange='this.form.submit()'>
: ]( f/ \8 h3 ?) o% P- a - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>( c) T3 f3 I* o* H" I+ j Y
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>" [/ |* Q9 c0 p0 {$ z' ]
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
- ]3 s! v+ a N" O0 K - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>% r: @0 ~' F9 b1 D; |
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option> L2 q& F [1 t8 V# n, X
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>9 F+ i+ j2 l# G' u- ^0 x
- </select>: s! ~! B1 e: @& r
- </form>
- o7 k: y# s0 x
/ r* q- Y) N5 H. q$ } v- <?php query_posts($query_string . $order); ?>2 Q# J$ X9 k7 X& j* h. R. b2 x6 G) Z
- <?php if ( have_posts() ) : ?>
& l; O! Z; r, h8 `( ^" c: L: U - <?php while (have_posts()) : the_post(); ?>
複製代碼 |