本帖最後由 pootor 於 2013-5-19 20:16 編輯
) w2 y' x& X- k: g3 J6 E! Pluguokankan 發表於 2013-5-19 20:00 
. g- R. ] j4 S" e( m你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。' n9 I# a, Q6 g; U" _
' Z$ P( O4 `; ~. e# C' [不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php" {6 E, c( T7 U: }/ Z6 N9 X
- $order = "&order=DESC";
/ ]" C5 `4 |8 ~ - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
0 r; S2 h/ a* v, S: [7 E - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
0 J; @# S$ I2 T0 u* Q( f! T. P - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; } q7 f& x; N6 B5 M3 y2 A0 V) h; z4 \
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }$ d6 P& h) p! h1 N3 k O6 V+ V
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }* Q- N+ d% O. z, k8 p! C
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
u5 M7 V4 x5 [% F - ?>- K @9 E4 T# K/ }- W
& ~, y! M. {- v+ c" n! ^! H6 L6 I
: K3 o t3 x* t2 G( x) ~: p- <form method="post" id="order">
/ {2 ?8 `$ v+ F0 u( f - Sort reviews by:
- z% M+ b1 X, `! V3 U& T' p - <select name="select" onchange='this.form.submit()'>
% m* S# H9 @. u+ S - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
8 m. M3 W/ S0 j& ]. t - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
8 x8 c3 Y' K4 c5 V: t" Y" i - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>( V/ m- w) t* Z0 S) O. _+ A: {
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
y+ y8 A* D- q+ G* L' L - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>6 D9 z2 g* k% d' S
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>. r. O/ b8 f; E3 k
- </select>
' o3 t; q1 ~( T3 L - </form>
( q/ }% v9 R9 w Z) E2 r" H
* V) z7 x. m( N0 p3 Q+ E, u- <?php query_posts($query_string . $order); ?>
; t- l A5 T6 T: P& @ - <?php if ( have_posts() ) : ?>& T& ?- |' ]. `6 s* j; h* a, P
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |