本帖最後由 pootor 於 2013-5-19 20:16 編輯 ' W5 L# h6 T* s0 X. l, g
luguokankan 發表於 2013-5-19 20:00 
/ M" g+ d$ Z: y你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。) K Y7 O/ S6 C9 @8 E/ h5 O
2 v+ k; D k5 v4 A( w. p; e不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
" n) b3 J y* H0 _ - $order = "&order=DESC"; h/ f/ C) C5 A# i- G+ F
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
& x/ L4 N8 L+ ^0 y- r - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }$ F! G5 Y; |" s
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
4 s: d4 \; k# o - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
* i0 {% S7 W ]" _; O2 R - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
- {3 ~: Z2 o" m; y - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }9 d( y9 B. K! `9 ]) F* {
- ?>
* |- k& B- r5 ^/ y; \ G - $ t3 N" T7 D0 ]5 W
' {0 f* p1 g% h$ q; a- t& ]' e- <form method="post" id="order">
5 ^# V2 d5 X* O' g/ g- m - Sort reviews by:
1 c% A4 v5 j3 D0 p7 D M - <select name="select" onchange='this.form.submit()'>
/ C7 s% M" M. m/ c% B k# { - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
4 Z. H. X L$ F0 E( w+ O' Q - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>' v& }9 ?1 b$ m5 Q2 K q, P
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>. U. U7 @3 _0 i* ~ T4 D4 ?0 [$ w, x
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
- o( r7 W9 k, |1 r - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
& o9 u" `! g. i - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
+ v+ g3 `/ `# X6 g% t& E( J - </select>) k6 o7 c" H K' p Z. X0 G. E
- </form>- C; T5 y, V- I2 A" E
- ; B+ T- p8 d; Y" N: G
- <?php query_posts($query_string . $order); ?>
& k6 z/ U1 y' E+ b2 D - <?php if ( have_posts() ) : ?>% H' N; J' J7 [3 f
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |