本帖最後由 pootor 於 2013-5-19 20:16 編輯
$ a. r. D9 ~1 `$ k$ ~luguokankan 發表於 2013-5-19 20:00 
* U; C8 ]( Z8 M2 L2 [4 p/ J你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。' z0 D3 d' n4 L( ~2 `
) R7 ~) @+ G% n& ]# T3 m
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
# u" D6 y8 \ a& i- b9 T - $order = "&order=DESC";& X% R$ x, d) i1 y0 J) Z( |( V
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
6 B5 s' V8 c( d- b4 p `" Z4 f - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
( W7 [8 w; U- \( U8 N% O2 ?- U - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }( u3 m- D6 c! t
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
2 }% m) M9 |2 Q4 s - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
, \8 e8 \+ X) l1 A - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
& n6 l+ |9 V' ?) [$ m7 M - ?>
6 v, w# A y& H: I
6 g/ A% C# O0 J1 q( i% o
( R" s6 C1 N5 }+ E4 v% L; h1 }0 z- <form method="post" id="order">0 ~$ O1 C/ e8 V3 Y0 F q' N" Y
- Sort reviews by:# R1 g& e( N" H, z' J3 e7 B
- <select name="select" onchange='this.form.submit()'>* p I. ^; i5 r$ D9 z4 H) F
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
/ y7 o" I6 N/ d; u* ] - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>8 y; p: l+ {# X( r* r5 [8 j) R, B
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
) r0 ]( A# u: M. [2 h9 a- Q/ H - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option> s; l6 b% A; ^! P6 n! B
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
& h4 A8 L8 i3 v: u7 C4 H b9 b - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>, d9 j) n3 P y L, Q- ?8 u
- </select>
0 t* p$ A* P+ o( U9 X. E3 i2 f - </form>
0 u( m, c% q1 c - ! ]( b2 r& w. K
- <?php query_posts($query_string . $order); ?> w8 S' }5 l7 @. m. m+ \
- <?php if ( have_posts() ) : ?>5 m D. T" c1 b- D
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |