本帖最後由 pootor 於 2013-5-19 20:16 編輯 # X5 A7 ^4 N: v w3 l6 ]* C
luguokankan 發表於 2013-5-19 20:00 
& ~4 l5 i) ^1 n4 l' m你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。! n" G7 T' P; j% h3 Y
* X1 q" e5 n/ N) T4 F不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
1 a* Y b0 s; J - $order = "&order=DESC";% W# M8 B( _, \! D
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
% i& O8 a) v& W0 A. }. P - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
* z+ B& k. e6 W' T, F& T - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }+ K0 L: m: j# [) z% I
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }2 ~* g) c) {- w/ l' L0 U
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
0 Y/ |2 F" W7 P; k6 r# g8 y - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }4 @* b# E3 a6 @0 F F! y/ m& x7 y
- ?>
+ e& l$ x3 E/ ]# ^0 Z - 7 J7 r; Z0 _( P
# z2 X8 Z& V& z* }- s- <form method="post" id="order">* B( c5 Z1 D h' j5 B/ l
- Sort reviews by:
! D" b3 s' c: P( J. }- |% H - <select name="select" onchange='this.form.submit()'>
7 y4 f. E2 F: P* @% ~: i2 ?! o( y - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
* s9 l2 ]: @- S- U - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>0 A7 g5 _$ e- g8 x
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>0 {. r& s6 f2 G& X4 O s
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
; K# ] E* A# [; c" ^+ } - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
7 u, D, n. r: n* _! D4 g% d - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>9 ]5 S ]- ~/ ^
- </select>
4 V8 S. W" G" p; l) W6 ^9 B - </form>
+ P" N, x; I+ t+ E5 j - - O% W8 o3 [8 x; a4 Q0 g
- <?php query_posts($query_string . $order); ?>
# }1 z$ X* e6 `. C- s& ~ - <?php if ( have_posts() ) : ?>
. \+ t* x- X C0 I1 D9 V$ C. Q - <?php while (have_posts()) : the_post(); ?>
複製代碼 |