本帖最後由 pootor 於 2013-5-19 20:16 編輯
0 a& {: m" s% d4 _0 D, k5 qluguokankan 發表於 2013-5-19 20:00 4 e; p# B3 l2 b R8 V
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。7 I- E2 ]9 m' n/ x' V
, K2 _- K, p- S! ?" R$ Y
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
: G& Q) O/ B! W" N0 U0 ^. n" S# h' B - $order = "&order=DESC";% O* V( b, K( r
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
d" @" {1 c% t5 ]' B9 \- X - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }# G% B- y' g) c5 `: I
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }: d% }3 j# Q* f; }
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
F: o3 a9 y0 ` - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
y; X" j; y' Q - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }. L+ s1 z; q0 }" g) e9 T$ h; P
- ?>
; M& B5 u- p* i, `6 A. o0 U - z6 G2 |3 p2 z( n. z* l( }
5 H4 E) C- X' l! p) ~. P& m- <form method="post" id="order">
7 U& @6 z9 u5 H/ b0 |' u - Sort reviews by:
; C9 K' B g+ ^3 L% ~/ I - <select name="select" onchange='this.form.submit()'>& i/ g9 j% w( }5 T1 H
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>1 C. {7 L% k& j3 ~$ ]9 v& a
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
6 \8 f* b8 E- |, {+ c - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>8 }/ l5 O7 E+ A/ g
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>' e* w1 k0 t( o1 [' E& y& D
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>, \. q" Y9 S7 G$ _5 C! {5 B" y
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>; P! u9 O+ p" f s) p$ L
- </select>
$ x3 J6 U! Y6 X* K" ^ - </form>2 w9 p' B+ w4 i4 C3 K/ n
_% t: `- i1 ?5 f8 P: N- <?php query_posts($query_string . $order); ?>
" ~3 _4 b* ^# D# Y- a) j' l/ h - <?php if ( have_posts() ) : ?>
) r: R0 R8 O( K) U" K1 E$ S - <?php while (have_posts()) : the_post(); ?>
複製代碼 |