本帖最後由 pootor 於 2013-5-19 20:16 編輯 / K, V/ y/ k1 v6 v! e+ ` f+ a+ J
luguokankan 發表於 2013-5-19 20:00 6 \1 f9 b5 j9 M
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
3 ^: q' g% j; ~3 T' w/ l! K
8 ]* o' `, C: @不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php$ Q" z+ s, Y4 k
- $order = "&order=DESC";( a& E5 A: O) u
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }( i: `8 a) W6 {4 N9 [! f! r/ g
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }# f3 ^) H/ ?4 j$ p
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }' w7 r; Q6 ^8 l1 b0 l
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }! W3 _% t9 `$ b4 X
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }+ r( ^& q/ g! u3 N( b0 s- S
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }: c% m4 S& W9 n O
- ?>5 z7 @" m3 D3 @1 P# z$ O' }
- # t$ _2 \. e- M
+ A+ c! C! H) ?* u- <form method="post" id="order">
3 V( R* ~5 P$ \ - Sort reviews by:
$ h* b2 R( J6 } - <select name="select" onchange='this.form.submit()'>- l7 ~/ v n' u# a- O/ X
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
, p+ M2 ?) v4 C1 k - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
8 f# h6 x7 ^; o, Q; M - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
8 p' w* K3 c0 o' R$ j' P - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>& f7 t* G+ i( }8 Q* X- o/ u" n
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
& Z# m# {2 ^5 e8 z b; X5 D - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
0 |) ~0 j4 R$ o# {( j, O - </select>
2 {( V6 V: n$ D' {! [" N# x2 O - </form>
( v" @: f) C4 U8 V* ~
! ]1 s, j! m2 N; }' S! n" \4 X- <?php query_posts($query_string . $order); ?>6 N" l! T( b5 e8 ^9 J/ v* E9 J% F! h
- <?php if ( have_posts() ) : ?>. ~3 K/ x2 O5 h, q
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |