本帖最後由 pootor 於 2013-5-19 20:16 編輯 - z2 P$ \4 D% f' `
luguokankan 發表於 2013-5-19 20:00 1 G8 \6 `6 R+ i9 c2 {/ ?# q" W" e
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。6 L0 l& b$ n% J. m: {; `
$ }# P _$ w f5 b不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
: i: R0 w0 B/ O7 w- v - $order = "&order=DESC";0 t. O" v% d2 J. L0 v+ p' U
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
' `, ^1 W1 a" j9 {6 e - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }3 S5 s9 F& j8 Y. G- H
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
- u6 R D+ o. Y; m( n5 B( S* S - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
, |5 J- H6 ?. b# q - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
; ~4 t- m/ f$ ]/ r1 D( p - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
9 }+ {- }- y' R6 T* x2 a$ ^ - ?>$ U% Y/ o% |8 y4 a4 E& D
( w& r2 ]# Y# J/ l$ @ \1 W
- ^% ~. o7 f/ \1 H- <form method="post" id="order">
# M7 C+ {: r0 F G$ v8 x% r* w- C - Sort reviews by:" z, I! O) H |
- <select name="select" onchange='this.form.submit()'>
* T& h; _ [( r) f. l - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>6 N6 H& u; E4 V$ x+ K
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>& K- G' K! @ A
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>) Y' g* y9 g8 f' v0 n3 o6 K+ Y
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
# L3 z4 A7 Q; B! r8 F5 f - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
1 [& d4 A; `' F' D) A% p - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>3 V m" u7 z/ b" ~9 I% k5 z
- </select>* Q/ R2 v1 V6 ~, [
- </form>
6 D u& \4 ?. W - 3 h5 J; v2 r: P* z F: G# F/ z* q
- <?php query_posts($query_string . $order); ?>
4 y! y, ~$ e! A0 u0 m) x/ C7 E: Z - <?php if ( have_posts() ) : ?>) v# W. i& Q3 F8 U2 Y' J
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |