本帖最後由 pootor 於 2013-5-19 20:16 編輯
* c1 ?7 X( ~1 a' M2 q0 Q) Iluguokankan 發表於 2013-5-19 20:00 $ D1 q6 p+ r8 X
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。$ y+ l! M( f/ v" l: r2 e3 i% P
: N; I1 X8 o- p9 g% w不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
9 E& `/ O1 B0 G8 S2 c7 e - $order = "&order=DESC";
}4 s2 s* I+ w% K" ]2 u - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }, l2 O" j" F! v
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }4 I T2 L% f3 V! ^
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }: Q$ D9 a& l9 w: ?
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
6 V. A5 Z& i7 s% U3 Q. | - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
. [) M8 u( u. ~ - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }1 m2 }0 c4 F+ e# l7 N# Q1 w- c6 {
- ?>
% I' J( j8 Y7 l0 ?: J! M) E% j* K - . D7 a" i; j; V2 v! N
- V. R( S$ a- _0 O6 t! B- <form method="post" id="order">
2 z/ A9 { M$ l$ |& m: a - Sort reviews by:3 X2 o4 A4 D- w
- <select name="select" onchange='this.form.submit()'>
0 j7 i% `+ v- p* u, D" S - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
2 i2 I/ }! E, C+ a) u - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
. ]; [4 R1 ]: N* B8 j* W - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
7 z/ T1 w/ x N6 A5 X; Y2 | - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option> S) j: E3 Y& ^5 `. F" Z1 B; z
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
% W" c' I+ e4 b C3 q - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>; b4 o1 W7 j) m! }/ Y+ l9 p' G
- </select>
- [7 R9 L. h& f6 C+ w8 p2 I - </form>
( q) h" t' I# U$ E% O0 N5 K5 t
, O- x8 c) |* M+ G& m+ ^, c- <?php query_posts($query_string . $order); ?>3 B) t8 h( M- i! b7 }! d
- <?php if ( have_posts() ) : ?>
+ q L& m4 z Y% U, y - <?php while (have_posts()) : the_post(); ?>
複製代碼 |