本帖最後由 pootor 於 2013-5-19 20:16 編輯 ) n* C# ^% u1 k; ]$ D
luguokankan 發表於 2013-5-19 20:00 
& b2 h# o; T( W. [' s你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。0 \3 p) ?! R: q8 t% h
) h9 _+ z" n* w: a, K/ q0 X7 [& ?4 ]不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
$ s( p* W$ I8 Z9 |6 K+ J" I$ a) D - $order = "&order=DESC"; j2 K, ^# i# W2 R. Z
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }+ T& I2 l) G8 D0 I: A' |8 n
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
# h; F* e' H& j1 K8 k& I - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }; g$ p4 i/ j4 }+ u; `
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
+ I q$ p: K4 E% ?3 o$ p" A( B* J3 ] - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }2 S/ ~+ k* r- Q' r. e, q
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }5 C D0 H# e. |- R6 u2 {
- ?>
, M2 s0 m; i; f$ `4 a3 L7 x# f
) n; f" D4 E; u( z$ _! P) n9 u# Q- 2 m4 Y- B1 A9 F3 x# x
- <form method="post" id="order">
+ C5 `% E6 f1 c& }+ `0 Q5 n - Sort reviews by:
- K* }: c% E, o. u' x$ s6 Z - <select name="select" onchange='this.form.submit()'>" {- F$ Z# o3 z( {5 _
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>2 O1 s4 b% G; N9 A M, H: Y
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
$ Y; a4 c* D8 g {2 x" J0 v$ U7 J: ~8 Q - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
6 x. m" ]2 [$ c @ - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
9 W& r9 t1 l! C - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
- V/ [, [$ P* D6 b, ?' G - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
" Z& ? N( U* e8 T2 U - </select>: u! y7 Q: V: M) Q z) Y
- </form>. V& p- K, l6 t( U6 I7 L
- s7 j9 l* J S) f, I" m0 S
- <?php query_posts($query_string . $order); ?>* O3 T8 B1 y$ ]8 a1 ~' Q4 h" `( ~
- <?php if ( have_posts() ) : ?>& }3 X3 |% K! l! z. O+ I
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |