本帖最後由 pootor 於 2013-5-19 20:16 編輯 - p2 w7 Z. [2 ]7 @- f3 J) D
luguokankan 發表於 2013-5-19 20:00 3 E1 T% p' W" G) B
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
g7 k Q3 Z! e8 w7 p# [
2 f) z u+ U; L不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php O6 L+ q2 i# k8 k- P6 }
- $order = "&order=DESC";; g: d0 P! g. _3 ?; p+ N7 u
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
0 `, }) p3 `' ]4 H: | - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
5 O0 t, G" J; K. @% R" v - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
6 S" h0 j$ ?1 O - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }( {0 c% r. `! x" t1 E" G; s" f
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }* W! u; o( z$ w, Q. b) d+ r
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
+ [4 ?6 v9 h/ c1 ? - ?>
' ?: P3 [: R6 R3 W- S0 p - 6 G; w3 I: A& i& y8 y4 _/ I
- 8 P C. H, A' b& ?
- <form method="post" id="order">/ G! B- h; ?. z) B
- Sort reviews by:
* O1 e- O; p# s( u* n; m9 l N6 r - <select name="select" onchange='this.form.submit()'>
" B; N+ t" C' S8 c& T - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
$ y5 T+ E2 k( b, h5 Z: Q& x: v - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
7 p+ n$ f5 b) e' P' k4 k& Y# U8 u - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>! [8 j0 C @0 `, p& @+ q
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
& f4 U$ _. d( G; k8 ?1 d- f+ S - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>: S9 M/ q. b5 k& b5 @/ U2 z+ R [( `
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>+ l8 D' y8 @9 {: I+ m
- </select>/ l( h! @/ v$ ]( ^9 D; M
- </form>2 v- t! I& l. E
8 _4 G* G) ?3 _+ y1 M- <?php query_posts($query_string . $order); ?> B$ F2 g- z2 L' w
- <?php if ( have_posts() ) : ?>
1 z! V) l5 R3 @( e* j! B - <?php while (have_posts()) : the_post(); ?>
複製代碼 |