本帖最後由 pootor 於 2013-5-19 20:16 編輯 . T V3 ^! N! ^: T2 V" e% V
luguokankan 發表於 2013-5-19 20:00 
2 W3 |# }4 n6 ^5 C- F) M你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。7 J9 W& n8 A$ _0 W! c( g" G
, T) S( s2 q) r
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
$ ~1 P5 Y3 k" x$ _ - $order = "&order=DESC";2 ?% ]9 A, ]3 a- x6 j% U) u
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
! o9 B7 b! L. W6 @8 p - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }: b- {, [6 q. Q: n5 f/ ]$ W) B {* w; t
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
m* G' D9 c8 x0 ]+ {: F - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
) {" J# i% f: Q* L" l, M7 y - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
" \9 E5 r5 t6 |" N% r7 G - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
' }) s, K& g+ p9 d0 ?% u - ?>
; X+ u9 P2 J. b) s) ]- u. i5 ?" q - ~8 Z, S& f% n: Q7 E, E, p
$ @: P; q$ I1 l3 w: {) I& s2 D- <form method="post" id="order">" ~5 ~- c' _* j9 L6 p! }2 F6 ~
- Sort reviews by:/ k' e# [# q( o" u
- <select name="select" onchange='this.form.submit()'>
1 X) j B& p% t1 B3 n - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
: J5 U* I( e* @2 ~ E7 {$ h9 U! c - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
& j& ]$ ]" n- t5 L6 L# b - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
1 g. o# f* Q, E6 X( p - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
* ?- E4 X, y" i* a- p. S$ _* f - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
3 E; ^" t q+ I. i: F - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
' q, x" l! A: X8 O* d9 ?* a - </select>
+ N$ T0 S6 W# f! D - </form>
2 z+ n% ?, t/ ]. v o5 ^ - - u0 h# t9 q9 U) B8 A4 v
- <?php query_posts($query_string . $order); ?>& c) V5 c* f6 ^5 R3 w
- <?php if ( have_posts() ) : ?>0 Y2 X+ U0 ]1 r: m( o" p5 J. b
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |