本帖最後由 pootor 於 2013-5-19 20:16 編輯 / l9 V( w) V! j* d
luguokankan 發表於 2013-5-19 20:00 
5 p; j2 ~5 G2 S* \8 N你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
" b) Q: H$ z9 o- k2 R( O/ P v; p: v5 N8 U h; n+ N
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php' { k% y- m% r
- $order = "&order=DESC";! z. w$ x5 L4 L8 B1 r6 M
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }9 }; u. y+ S3 A5 K7 z
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
$ X. R* ?! v- q* B( L, I - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }; s: a |/ [& |; U) N
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
0 A! z" w% W' [4 W7 b4 `0 U; E - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
5 x/ n" Y) V% U* } - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }/ y* Q X& X: q( A
- ?> f, A/ q% x# B; i" i
- , `- k7 o, Q; u( m7 j" b/ I. q# C
- * G+ @) J0 @' m0 ]5 }% t
- <form method="post" id="order">
$ R- y0 M9 c n7 U1 z# { - Sort reviews by:
$ P9 Y9 O2 b* r* u - <select name="select" onchange='this.form.submit()'>
* r& q' S3 j1 d7 V0 r6 N - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>( K h5 |8 C0 z( p ~/ d+ N
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
, E1 @9 @+ {( K2 s8 V$ w2 K4 S0 E6 \ - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>9 q, ?3 k" Y' Y% k
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
/ _4 f' y" A' |, T - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>( k: D: Q: Z a1 O) Q
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>1 P9 Q& @4 P& X, p0 O4 o/ k" T
- </select>7 S2 }( M, I9 o) ^- i8 z6 u
- </form>
9 F5 b( W. I# \: H) J - * G7 @" h% K+ [+ z2 O
- <?php query_posts($query_string . $order); ?>
' A: p/ ?; a8 o2 Y- X) U9 x - <?php if ( have_posts() ) : ?>
- V) ~0 h* Z* i& W - <?php while (have_posts()) : the_post(); ?>
複製代碼 |