本帖最後由 pootor 於 2013-5-19 20:16 編輯 : S* S- b) Z0 k. W( K( m, c7 W
luguokankan 發表於 2013-5-19 20:00 0 `8 H6 `4 a( B% W) F: d' f! }
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。' l, B& y: I% I2 D; S
0 }2 J% {" P, Z8 o; o% R
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
( x Q% V% H( c" ]" R+ j - $order = "&order=DESC"; K( a7 d0 h0 {3 u: ?, v. z
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }0 o) b" Z2 w3 k. @! B; @
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
3 B* W" ], ?" C1 t/ \8 i6 v* G - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
$ U4 E' j$ B j - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }2 l9 s7 J# b, W A7 t9 _
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
6 Y1 A. b; Q7 z8 Y - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }% |% t! o Y- o* |( A
- ?>3 f8 v) c& ?7 w! K2 k$ Y* B! X* C
4 N( ]& W x2 c* Y) d6 e; _- ' Q6 g1 b( G4 p
- <form method="post" id="order">
! ^) u) p T9 D+ Z) ~/ O - Sort reviews by:/ |9 t$ `. i+ k5 S& O
- <select name="select" onchange='this.form.submit()'># Q& U9 p" u# E2 j
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
5 [2 y9 m N9 ~/ I) \% J: Z - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>7 N2 R1 F$ j" } i
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
, E& f9 p! j& h1 `9 @ Q - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
- w/ D5 z% i9 P+ Z) E - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>6 A* c/ ~0 C$ L' i- @' g2 X
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>* L4 T+ W+ M; ]5 ?
- </select>
6 z* k# [* H2 X - </form>1 O) P Y) O2 F7 B8 U4 s3 j* ]7 Q& [8 s- Q
- ( F* h# ^0 M6 Q! e, S! q
- <?php query_posts($query_string . $order); ?>. p7 h$ `$ Q2 h$ a B
- <?php if ( have_posts() ) : ?>
5 b6 t c/ I: O7 _! v" a7 M, b4 I# O# G - <?php while (have_posts()) : the_post(); ?>
複製代碼 |