本帖最後由 pootor 於 2013-5-19 20:16 編輯 : M" a. r& w% ^2 }
luguokankan 發表於 2013-5-19 20:00 
( g2 H9 r1 X. s# d. Y你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。6 p1 u5 U- S# t4 l, l
7 q/ T3 W3 }. {! m6 B- ?不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
4 _7 x& P: b, _4 K1 O& V, K - $order = "&order=DESC";" w, s- V& E8 o$ F; j; ?
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
: @( N0 ~2 }2 o2 {2 H5 X! ~ - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
% ^2 Q1 A6 M* N7 T0 e2 ]" l - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }0 K6 F6 f5 l) b7 C6 p
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }+ h# m5 l2 S! f" t1 a" v6 k3 `
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
: b- C& M' H5 ?8 [2 ?; N0 [ - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }/ R' A: C3 x/ U- R- V* u w# d; n% k
- ?>
w0 h7 S& B$ c7 P. m
* s$ C- E8 V# N# @" d0 ~
# Z$ e5 B3 m0 z( ^- C6 n- <form method="post" id="order">
- g( y- P& |# J7 x2 O - Sort reviews by:
6 ?+ V) Q; n; e2 s. J, m4 Q - <select name="select" onchange='this.form.submit()'>8 Q) ~7 E0 K8 V7 g( f8 l0 Y
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
6 l* `( ]! b( \) o( E# H7 z - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>. m9 P6 x d2 T( u! [1 l
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
# y5 M, Q2 H2 P" b G - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
' R! ~0 j7 R! `. j/ p8 Q - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>& E p/ j, E7 D2 A S: o* `0 m- t# z
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>( ?' {6 y3 u3 t' f7 S+ _
- </select>
6 q, ?1 r, T' s1 ?- q1 y) m8 H9 V - </form>
+ i& R4 g" V% p1 R3 i
, ], |( J4 @8 Z: }/ y- <?php query_posts($query_string . $order); ?>
, s6 `, h/ j k) g S5 m - <?php if ( have_posts() ) : ?>* {% E+ b9 Z1 Y: Q2 c# X0 W
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |