本帖最後由 pootor 於 2013-5-19 20:16 編輯
1 J y' R6 Z# r: I& A7 I% I/ dluguokankan 發表於 2013-5-19 20:00 2 |0 |% M5 j) m! U# E
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
( a% S$ ?; F2 X, ?& [! N- a, H* E/ y. @6 J- k4 E
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
. }+ }% i7 s0 B6 R5 w - $order = "&order=DESC";
9 {! S5 O, i4 X - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
9 t1 m" M' {3 F9 R' N. ] - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }9 S2 v) W% K7 R% n: R$ G; U" B, F
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
# s8 z3 R6 Q% y' c/ D- Q P - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
# q; U0 K" S& m1 R9 X% L - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }: F( B: c; ]+ n- X$ @1 V' Y
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }0 p6 c3 a8 t% l4 w" _6 D" Y: t
- ?>
2 S X$ L7 i! F2 S* ^- m - 4 b9 ]! @, V8 H" M/ q
- ! _6 ?/ E$ a- o2 _7 Q* a
- <form method="post" id="order">
* D1 N$ }! ^ i7 P* @- d. f w# X/ N - Sort reviews by:
6 d8 o4 w0 p, g9 x+ N1 U4 C - <select name="select" onchange='this.form.submit()'>
: D( w" ^# [, _# Z! @$ L - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
9 ?( D* v1 c0 I+ g - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
" p# `& f9 B; ^5 W5 c4 u - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
( N& L% L# f- [& t# @+ w) y* `! Y5 o - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
9 H; T' r! H; I! x" {8 g - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>, R; D& q. N* e
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
+ _9 P9 Q' r b - </select>/ r7 o; ?8 g9 m( S! i* q! N
- </form>
0 ?) \2 E2 l" K( P/ y. o- ]
# h$ y- u% I6 @6 s& z* J- Q+ c- <?php query_posts($query_string . $order); ?>
( A+ G8 n2 d2 Q0 E T# w i - <?php if ( have_posts() ) : ?>
. N) K1 I9 M; Z, o - <?php while (have_posts()) : the_post(); ?>
複製代碼 |