本帖最後由 pootor 於 2013-5-19 20:16 編輯
# i! [+ @1 l' B; \( S5 iluguokankan 發表於 2013-5-19 20:00 
( s) B% ^% d" w& _, F你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。0 [- i( l9 Q0 y k: _3 P, A" E$ ~
! c( R/ `4 R6 _3 `+ N
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
" g' K+ [* R' h: z) U' l - $order = "&order=DESC";$ f2 S/ A' ?& `2 K
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }) ^4 v5 j- n3 ]5 M( P8 [
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
9 c* a/ z* ~9 c) j2 t - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }" a' @3 ]' A' S% ?
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
3 M' S0 g# ]8 G! L! ?7 t - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
5 a8 i- f- x0 Q3 r c - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }4 m) [" g/ f1 w
- ?>! Q" X5 x2 p- {( |
- W# I3 }2 _( [
& K. B e S- X! J! `, V0 M* z1 s0 m- <form method="post" id="order">
% W0 p; Q9 s) y) p: H# x1 w - Sort reviews by:
3 E5 m% ~" z- a5 q3 c - <select name="select" onchange='this.form.submit()'>2 q0 e$ m# E& d! S; n
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option> ]5 z) i9 i. l/ t1 q0 k
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
0 Z4 {% K+ S. r- Z* p1 y - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>9 z$ D) j: ?# r9 i6 p
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>4 h: f9 J* y9 D7 K* ~
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
8 X2 I/ _( r5 v0 v/ ~6 e - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>, i; `% H' C; c7 l. d
- </select>3 U; N6 i4 @- j& V4 G- p9 Z
- </form>
, A& p: j1 @3 M G/ y# v - ; f5 C1 r% N1 }8 a7 L8 `
- <?php query_posts($query_string . $order); ?>
1 R! `2 y: j5 A, |. S - <?php if ( have_posts() ) : ?>2 c8 G4 T2 R8 {' ~- k0 b/ p. T
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |