本帖最後由 pootor 於 2013-5-19 20:16 編輯 5 T( Z, K" f) E u
luguokankan 發表於 2013-5-19 20:00 
$ |% P0 h( C- O& t/ b你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
6 z( }% _9 U" }& R/ |' v
$ t5 C- ]' X/ W4 ~# y# h' l不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
2 V! ?" p; }5 b. s! |! Z - $order = "&order=DESC";
5 F: | I* T$ U$ e% r" r - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
0 [+ W! b3 ^* D E- i, ?0 J% A$ R b4 D - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }' P7 s4 W! n" Z, D. D; w
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }- x' @+ K) C( J; M
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
; t& x$ y! ^3 F3 x* ~9 F4 ~ - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }' V& X8 v% }9 h7 z, W
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
/ O% s+ L) a% L& s- q* M6 B - ?>
7 P! }& z! F9 Z: b; | - ! _5 V0 t' S$ b: m
- ' ]; |0 `1 [, m+ I, e7 P! Z
- <form method="post" id="order">
+ k! E5 {8 s/ `0 k - Sort reviews by:
- [. m2 r4 @( {( r/ @/ j - <select name="select" onchange='this.form.submit()'>
0 ~4 \( }! ^% n0 y$ E& [3 W+ ` - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
% X$ u9 [: M, q - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
0 F8 Y9 n- ^- L - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>/ Y/ l2 x6 F3 p2 O
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>* ]% H' A0 e& M9 d0 M! @
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
1 E1 V2 b( R3 F- }0 y8 Y" O - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>: O' \ J/ c1 r! \8 S$ `3 J
- </select>
+ v# \7 o! s" O% ]0 u - </form>' Y/ g' B: H9 b/ B/ S7 K5 T+ H$ D
- ) ?, I9 W$ ^' E5 j
- <?php query_posts($query_string . $order); ?>. M9 g* T4 C( t! d
- <?php if ( have_posts() ) : ?>
9 C/ l5 ]( Q" _8 h f, D - <?php while (have_posts()) : the_post(); ?>
複製代碼 |