本帖最後由 pootor 於 2013-5-19 20:16 編輯 ) w6 ]# U% L9 t+ l. x
luguokankan 發表於 2013-5-19 20:00 
3 F5 _$ b5 P b% `; B8 x% f) n你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
6 j; s1 E) P# _( y X1 k+ v1 |: k1 R+ H* @& ]6 G9 R
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php: v, n$ W% r! x; d: D
- $order = "&order=DESC";
- |* P! J& p- j4 v, p V3 L - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
3 t2 _' Y+ \) U - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
9 F9 I/ Y3 D- E9 |! k! W p3 M - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }% h6 e# ^0 B2 v- |/ c
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
, v) H% o$ r9 F - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }# e# D/ T7 u, T) S1 U
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }. i3 J0 ]2 S# n7 R
- ?>, \, t; T: y- y" M7 b
7 X& b- D' E8 z z- 0 ]8 V5 @+ Z. Y
- <form method="post" id="order">
4 y5 J* E* D* B - Sort reviews by:0 j* }) I2 `9 X" P& ]$ A
- <select name="select" onchange='this.form.submit()'> Z4 E& t! A. @, ^, J( o, [. l
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
0 E _1 G; a! g7 R$ z7 Q* E - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
$ }: c- A' S& N! y# k8 M) C& }8 u% y - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>. y' q2 {# z# x# I, s
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>0 \7 i' C* n& }1 k. ~, m9 X
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
$ z7 ~6 s! i; |$ k3 x7 P) e# } - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
2 b" U" |: @4 w0 {% X' S! ? - </select>+ e# Z& `- q! z+ w4 G$ r
- </form>
' \6 S, P K5 O; L, A
/ O0 \6 }( Q2 e1 V1 @: |/ w- <?php query_posts($query_string . $order); ?>6 z4 z E( B* G* Y. B& Q1 {
- <?php if ( have_posts() ) : ?>1 r9 U0 x5 @9 p8 I6 _
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |