本帖最後由 pootor 於 2013-5-19 20:16 編輯 g% _: y! {) S( f2 N) _# S% y" J
luguokankan 發表於 2013-5-19 20:00 2 ^6 P$ S9 t4 Q) g) f0 K' j& Y
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。* s! [, i; z0 r3 P- n
# v0 t$ d; }+ U% h( e
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
' d/ f$ R* a+ G# D5 Q) d5 [ - $order = "&order=DESC";) Q' l& R ^/ Z7 E1 e& c. q0 G
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }8 W7 X) a T$ w' n2 l* D% r' a7 \
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }/ `0 e) z7 u) l2 b7 C
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
. s1 Q9 B, X8 ~. g9 O e$ Z' Y' \3 s - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
$ m+ [+ O3 F) P/ |, P' p) L' t - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
2 L, a( I) I6 M - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }/ Y- M- z q2 f N
- ?>
6 W) P& ~ J6 j8 k% d5 e8 n: T
! a- Z) J% W& p8 a! \0 P% F* N* q2 `
B& R% V# _) l. h- <form method="post" id="order">
( q& D6 g3 m/ d - Sort reviews by:* p2 C i# }6 q }# B
- <select name="select" onchange='this.form.submit()'>
( `- W# W7 ~0 T& V - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
' X& t" z* r: y9 P; T - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>+ D, ^. {- b6 o' N$ z R
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option> f4 S, | s5 m" g
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>3 S d$ q5 F3 { l X; n0 d! h
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
5 X+ p4 t' ?- V/ X4 b - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>1 Q. ~8 u7 P/ P
- </select>
7 N, N3 \# Z4 J- B. A, T - </form>
0 k) m* b F/ h4 O8 @( b
4 `0 H9 r- d. `/ Y. D; P- <?php query_posts($query_string . $order); ?>5 G" o" F- j& \9 @ W. |
- <?php if ( have_posts() ) : ?>
9 b) ~4 _ a, E2 U; D6 G - <?php while (have_posts()) : the_post(); ?>
複製代碼 |