本帖最後由 pootor 於 2013-5-19 20:16 編輯 - z) _. @; ^, g o6 N' T$ A. x) m
luguokankan 發表於 2013-5-19 20:00 ' ?9 ~1 T* f" X7 d
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
! w1 F7 Q2 W% c( i
. Q7 F6 Y4 |7 g不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php* i5 x+ \5 Z" G i5 T: e' [" J
- $order = "&order=DESC";
& W7 @' t1 Q% v# z4 E - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }( k& v" g o+ |/ g& }1 ^7 O w
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
0 }6 u! w! j1 ~ - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
* M! l4 n5 Z- q - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
/ s, c: Q' g2 [# v- J - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; } d; E+ L1 |5 }! ^7 e
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
9 B5 g# x) n, j' U7 H - ?>9 D5 d/ z: R/ I3 q
0 Q, X; c, O9 c% o" ^" T- b
8 z" j" {- |( g1 X5 _, `- <form method="post" id="order">9 K1 H& e% T% w( p1 T2 K. @
- Sort reviews by:
1 M7 V" D5 P& I1 J" ~ - <select name="select" onchange='this.form.submit()'>
) p1 \- x8 G' G& e) q - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
x+ g/ `1 ]8 p4 ^5 a3 E - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>8 K' R4 h1 i4 P$ Y; g
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>: q( J; |" d+ G9 r- u/ Y
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
4 [1 O* D: T* I* ?, n - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
& V+ l9 ?* K8 F( Z* ^! L - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
: d9 G) w3 c# _- g - </select>- \; [: ~7 k7 s; Y5 h5 y% S
- </form>& N: S- ?1 a1 R Y \, a
- # f& F9 n: W+ F2 B# W: T4 W
- <?php query_posts($query_string . $order); ?>5 P* J3 A( @" Z4 ^) G2 W' P
- <?php if ( have_posts() ) : ?>
2 N( n2 D$ j) C% ]2 N4 p) C - <?php while (have_posts()) : the_post(); ?>
複製代碼 |