本帖最後由 pootor 於 2013-5-19 20:16 編輯
4 J: R# r0 M7 H% [9 Tluguokankan 發表於 2013-5-19 20:00 T. o$ [' @8 w8 C
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。# T- `" w8 r+ V# i2 u4 I1 R
8 c; p% d+ }. E, x! i1 r
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
4 A9 F! k7 g( o& H% v- }5 @ b - $order = "&order=DESC"; R3 \5 R: a9 C3 s2 ]) H
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }4 ^" P. j' s& ~1 e2 e( ]% n4 k7 Y6 h
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
7 B- `( c2 [& ^% Y- v9 M) }2 t, ^ - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }) [0 A/ t& P3 @8 c
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }% l7 Y9 p% q, g' D7 @7 U
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
8 w8 J1 ` Q$ p- b - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }* R* d3 U% |8 i3 y, }' a
- ?>
3 w4 k) U" T) C7 R @$ }* K - ( H6 T6 @6 F3 s0 Y7 P# M4 I6 z: u. u
- " |- u4 I# R; c0 V" f% D4 s# g
- <form method="post" id="order">
7 J# Z: o, H& ]2 k - Sort reviews by:
! q p5 _$ S" h - <select name="select" onchange='this.form.submit()'>3 X0 ~/ k2 n/ z+ u \7 \. Q( k
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
+ V5 X& y' X% x$ o - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
) _% J& O6 `6 c; Z - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
& p0 z/ f& R. {5 h2 X - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>1 Q' _* b" }2 p
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
- o! K6 i4 S" s# x1 q - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option> l# C4 h' y9 i
- </select>, F1 G( f* ]% @) A' Q
- </form>0 N* D1 {# u" N- p% ~- k8 r
, Q% }, S8 K( W2 a& l$ B6 `# _- <?php query_posts($query_string . $order); ?>) T5 S/ A8 a& x2 ~* C+ m6 i
- <?php if ( have_posts() ) : ?>- e8 p7 w6 B: P! q4 |. Y9 y7 n
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |