本帖最後由 pootor 於 2013-5-19 20:16 編輯 # ?/ C, k g( `& z9 d! ]
luguokankan 發表於 2013-5-19 20:00 
1 J8 S/ A, A/ c2 H你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。) O: ?- P' g: q
4 L$ d2 O% Y! M, b+ b$ g
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
. k8 q( X! d' k F; X Q - $order = "&order=DESC";
4 Q9 k$ t; j: C/ W0 G$ J - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }! w N7 \. n& H1 L3 U3 Y/ R
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }3 `' g* A5 O, {+ ?* j+ n$ V
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }+ W5 ]8 w6 s) h9 d0 Q
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
' e& x* K9 {. H! z) I3 Y; s - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
: {; t/ x- i" `: f - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
- V% K, T# b( E' F( V; J3 [. ] - ?>. F8 I9 ]/ e7 c
- / U: D0 _& i" n& o8 F
- 1 t2 Q1 ^! ]+ ^8 A' p) q$ r3 f/ i* @
- <form method="post" id="order">" r4 {8 K4 U, u `
- Sort reviews by:
3 F5 j! \0 M/ ]* R& r1 ] - <select name="select" onchange='this.form.submit()'>+ i$ `' Z+ n: m( }
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
) r7 h9 I% k1 f! B - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>: P& y0 ]' @3 ]; l" _
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
5 o& _; u' a+ @6 b" g- K - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
) X3 p4 f) V. _5 Y - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>( K/ G% ?$ Y6 o! b7 K0 v( W
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
9 S I* I5 Y$ w3 E9 K6 D9 F - </select>7 n; c, C% V! ]. a" X' O5 [% V
- </form>
% ~* f s! P5 n' F - 8 B5 g8 e5 D. G% \( O
- <?php query_posts($query_string . $order); ?>
3 |% e* [2 f/ G+ s/ f1 c, T$ }' R - <?php if ( have_posts() ) : ?>
8 `% |# c1 {9 S7 y& S% p - <?php while (have_posts()) : the_post(); ?>
複製代碼 |