本帖最後由 pootor 於 2013-5-19 20:16 編輯
0 H* w: s9 G- d6 a/ ?/ e, |luguokankan 發表於 2013-5-19 20:00 ! ~8 O% P! m- t9 `2 p$ k, m8 y
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
6 B* ^& M* Y# d
8 \! ~6 h7 T3 i, z' k) f' X z不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php/ f" Q6 S7 L6 `5 m4 z7 i% P
- $order = "&order=DESC";! j( P. U3 j# O& k- l- b& H& b$ X
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
$ Y8 d/ F" q$ V - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; } d: _) [% u# \9 I4 ~1 F9 d y
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
; t! d* H8 K4 a* g+ S6 T - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }2 g% b( d2 E# Y* }' M* r
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }5 J% J" ?4 _& ?7 p! v. b) g: s
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }2 a. P- e2 I* f. T/ N, Q
- ?>
4 @6 q" G- r* z" n S - : y6 }% n' N; i% T. |2 b( l5 T
0 ? S' i( H" {; c4 m- <form method="post" id="order">4 Q3 m. u9 a9 }) B S, @
- Sort reviews by:
3 H0 N2 t$ Y: f& B& y# _. N - <select name="select" onchange='this.form.submit()'>8 J. m: \ k1 H1 b
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
2 R5 V: g/ x% n' c9 t9 G j - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>* y+ {; o5 b" x& V0 f- N
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>- `1 A3 S$ `- J8 C
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
2 E+ F- b( l4 q# W. ? - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>4 w- ?4 A$ r$ o
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>9 C/ N5 ]( |: E& @
- </select>
- _. M5 A" M# I" x& R - </form>
9 u+ g1 A, w2 o+ T$ H
/ O& \' o$ K. A9 w4 F' D% S4 J- <?php query_posts($query_string . $order); ?>
9 G& p5 i' k6 l2 P3 s - <?php if ( have_posts() ) : ?>
7 ?8 l- w- n5 b - <?php while (have_posts()) : the_post(); ?>
複製代碼 |