本帖最後由 pootor 於 2013-5-19 20:16 編輯
" w: Y: Q8 V$ |' Xluguokankan 發表於 2013-5-19 20:00 
! K6 G0 Z, q, ?; m' R1 H你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。7 `1 \ u9 q& Z2 K7 j1 L/ u; q
2 S1 J% G1 x' A, U不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php* h1 Z$ h# H8 [- {! r1 ^8 q. H9 E
- $order = "&order=DESC";
4 K: n& b/ D" I$ D - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
$ g+ x! e$ i5 K - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }! J% Y8 O9 i) n
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }) l1 o* a# e7 M
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }# P! d1 g# u' W
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
9 F2 U- f2 a6 m - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
) d/ C _+ D% E t' p* Z - ?>
m* `1 s8 a* D" c9 f9 Q3 k# l3 W4 g - / ]# L! Z: E+ J0 Q+ v# ^, X X1 ^
- ' _+ q! s" r$ T' ]/ ^% |$ m6 a
- <form method="post" id="order">2 Z0 U. \) V( t) \# r3 ]1 {: S# ~/ P
- Sort reviews by:* p4 n+ s# Q" g# ~. f
- <select name="select" onchange='this.form.submit()'>% ?) i8 B5 b! [, q
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>% F; u! D( B3 F& U
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
% t2 R8 b D, C) [/ ?6 Q - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
) [; i/ Z6 r( N* v: g, Q - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
% @# ^0 Y% }0 B - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>5 X% `( t+ O) q# k# ?
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
6 N. s% k* Y2 _- i - </select>
9 S$ l& {' K+ J& t8 b - </form>
. d6 P8 }$ k# [ g2 _7 A1 ~
& S" ^) X* N; x* n0 W+ D4 b* H- <?php query_posts($query_string . $order); ?>! O$ L" u- T! s- s: M1 S% B, D
- <?php if ( have_posts() ) : ?>6 j ^# C4 G2 P: W9 s
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |