本帖最後由 pootor 於 2013-5-19 20:16 編輯 8 \0 w1 h3 ~1 O" {% j+ Z
luguokankan 發表於 2013-5-19 20:00 
4 `4 V& Y, Y' `( t j你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。. V6 n- c/ K4 H9 h% g. C0 R
y1 C+ m5 L% e( D0 {# Q
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
7 H! b7 ~' T$ O - $order = "&order=DESC";$ ~! K( h1 P$ }) @" {
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
+ E8 E5 `, \, m2 ~$ E) I - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
! }% D" e4 ]- _; B - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
$ S. R0 I! H0 }! }% L1 N - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
- [% E: C; M: j" a4 G/ D - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
- u3 n3 v3 I1 i; h9 v - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
( A! }6 w. d- v& D; D - ?># j; t$ ~$ z: m9 P9 b* n
5 F( t) G( Z4 C/ t
6 t& I) K8 n1 E) m+ b4 l! U- s- <form method="post" id="order">9 q; H6 O/ O: ^! K9 R5 k2 m
- Sort reviews by:
9 h# V% s# E7 h - <select name="select" onchange='this.form.submit()'>
4 E3 q2 |& r) [9 N4 F. F. A - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>( @4 X0 {/ \3 F* _% ]" ~( o; [) w
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
4 o' ^% R& ^ H4 v5 M# r& \ - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
7 v6 q+ `8 l1 V' {- c+ S. c - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
$ g# O7 g7 s, A" Y* h3 R( D - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
2 }5 ^$ d7 `- K) U1 m h% p - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>; a2 ]& v) {, R: m
- </select>- S4 z6 M5 t# `
- </form> x, \- J& K% n* T/ v2 |0 {
- ! M5 K: i" [5 }: Z! h
- <?php query_posts($query_string . $order); ?>
' W/ D2 K* t) q, d3 c8 v# t - <?php if ( have_posts() ) : ?>
( d3 i$ t4 Q3 {9 ` - <?php while (have_posts()) : the_post(); ?>
複製代碼 |