本帖最後由 pootor 於 2013-5-19 20:16 編輯 0 g) V G. h0 _" V4 N# l# v4 Y
luguokankan 發表於 2013-5-19 20:00 / N7 w- @. {4 Z
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
+ K+ l" M2 j9 i# m; T5 c' E
; e) x. P& B1 h/ k/ ]不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
4 E! K; X; k8 z/ x: h( Q - $order = "&order=DESC";' o1 G2 R) A$ o! W$ q; Z$ J3 Z
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
- V& {4 Y7 b( ]( b5 ` - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
0 y& c& C: Z- x$ h" g+ r - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
1 J. W' X/ \/ w5 t - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
0 M$ l9 E7 P" n6 q7 c$ D- q8 g% f - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }( K4 j- d6 @, O* m0 K( Y; U. [
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }% E2 t* a. K' Q6 X' _4 z z2 q" V
- ?># e3 A+ y; v2 t5 |
- " C7 `" o3 J/ T+ y
" C9 ]' ]. x. Z9 K- <form method="post" id="order">
/ [! k! S2 e8 S7 } - Sort reviews by:
3 F* }7 M! @& u2 F) T% K - <select name="select" onchange='this.form.submit()'>
; l' z2 J7 ~" r$ @) w" D - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
( }4 Y5 x0 x2 k! h) T4 f# X - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
( m* s, j* R/ b- a! h3 V - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>- B) Q! _% s) }: X
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>9 C* D$ C/ n8 ?3 _ A+ |/ G
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
) l# |9 w0 h3 N5 G3 ?) x) |" [, H - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>2 I; s7 s' e$ x. c7 X- p0 @
- </select>
1 @" I4 k8 h' f+ y, z - </form>0 e0 F1 l) m% i5 e0 E. u
' {1 t8 f! K- S |+ m {4 y* |- <?php query_posts($query_string . $order); ?>( [, d- h1 C% f1 t8 ?3 W
- <?php if ( have_posts() ) : ?>
( ]7 q1 E A3 E, v: f9 r - <?php while (have_posts()) : the_post(); ?>
複製代碼 |