本帖最後由 pootor 於 2013-5-19 20:16 編輯 ) E0 C; V1 Y3 B! S$ ^
luguokankan 發表於 2013-5-19 20:00 
$ O/ l+ w# S3 G; u; | O你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。, Y# }; @ \8 H( ?& Q
7 L- o5 N* w# e5 ?. a0 v+ x/ E不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
# F& y# s: ?; I' v% n - $order = "&order=DESC";
: `4 H" l' m4 m2 {5 n4 ]7 R3 |1 ?2 u - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
0 p; @, U2 x! F$ i t - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
" I \) c0 X, S( L4 B6 C) C - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }9 S$ Q6 f, t- i4 l$ N' I
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
* M# J/ S& o/ I; c+ \% J7 | - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }3 {8 c! s \- ?( v
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
$ p/ \9 D: i( T: ?& X/ x - ?>
; C2 F) B7 I, k' _# n1 \; V* ^ - - ~( V* O2 j- K9 ?7 s* e% e
- 0 s B- k$ D$ E. q" Q+ I
- <form method="post" id="order">" w! i3 \& l0 b5 x% }/ J
- Sort reviews by:
f0 P+ d9 h( L1 p* t9 e6 j - <select name="select" onchange='this.form.submit()'>
# D6 [: d: C, m' W) ^/ i7 e$ | - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>: p* V4 j3 K1 n- d7 f( m
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>% e; B9 W3 P l5 u# k
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
9 @- g5 M" ]9 G! ?* T! U - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
" @7 H6 s8 y9 c" ^ - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>+ @* d- @+ T B, }) ~2 @& \
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
0 V$ }# c( P9 Y q+ e - </select>2 ^/ I" p" g3 b( q
- </form>
9 h5 Y. d9 g3 T) K4 l. B5 X' p
* b8 i9 p2 @4 A$ i& ?; Y- <?php query_posts($query_string . $order); ?>
* {3 X' T9 P1 L3 D1 O9 F0 c7 D6 U0 h - <?php if ( have_posts() ) : ?>
9 i) ~/ F2 r% [) V4 C1 L7 t - <?php while (have_posts()) : the_post(); ?>
複製代碼 |