本帖最後由 pootor 於 2013-5-19 20:16 編輯
6 A0 N3 n" y- I" m5 D0 nluguokankan 發表於 2013-5-19 20:00 
8 G% \3 V# v$ W, q3 o你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
. r& |: O, N' B7 ?4 t3 E {2 V: {$ k' g2 C5 q1 e
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php! s, e6 R& P/ ?* q8 t# O
- $order = "&order=DESC";
3 R) W* X S6 L* E0 z$ c5 G! e - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
0 Z2 z# ^3 w% \' {8 F - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
' g' m' W4 K, C1 _9 N) A - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
# y1 B% ?, d# k - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }/ D& N( P# R6 d7 N% w
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }1 Q2 }( M' P. v) X* {1 E. m7 u! i/ |
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }* s1 [% ~1 i+ J5 H! ~
- ?>
7 b( \! }- p0 ~- `- f* n( _
( c9 X2 i9 F2 B: @$ F% S- 3 I# q2 A: K! h- J3 V/ a$ q; P
- <form method="post" id="order">
% `% c) u4 r. ^% \0 ] - Sort reviews by:
9 T/ E4 e, _; E: s. h. D - <select name="select" onchange='this.form.submit()'>
+ W2 H; F" b: g* k# s0 i; s3 _ - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
2 Z& G) A7 g9 k. ^ r7 f% V, V - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
X- P/ b3 B0 L& A - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
/ D7 T1 G. i' C2 \0 I9 z) E6 c - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
9 ]4 A& N0 I' o* O2 v0 a% [2 C$ t+ Y - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
" c4 ?) o# M' p' R: d/ x/ q - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>* {7 b3 L: P" p# f" {
- </select>3 o7 M5 I7 w3 f1 t
- </form>; H9 d% p/ w) _; G) I
- 4 r5 T) D2 o3 N6 O2 L* l
- <?php query_posts($query_string . $order); ?>
5 l) G8 s8 M+ ?/ y) |! A3 Y9 ^ - <?php if ( have_posts() ) : ?>- r% W- }, e1 \5 W" x; V- M; t9 ] C
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |