本帖最後由 pootor 於 2013-5-19 20:16 編輯 ( [1 T1 Y, S" ~9 s, p# k
luguokankan 發表於 2013-5-19 20:00 , w- w+ A6 X/ S7 S+ H' {' C
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。- |7 G; `! W, z# c6 @) r5 L
! N; R i- W( x不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
( F$ x% l6 Q! r( R' v4 Y7 M! k0 } - $order = "&order=DESC";
. a3 [8 ]6 `+ N - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }* i, x8 G! D, _, w$ w
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
: x( f v% G1 z - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
% M- o0 ]# s& |( ], G( j - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
$ z/ V* ^$ Q0 u3 y$ s4 N" b& @! ^- T - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
3 v- \) P: h: B9 Y4 q$ i/ _ - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
! H* A3 I: G3 Z - ?>! `! o8 @$ \( s: b+ @" q2 D
- + ]9 n5 P! |( i! `
- g, }2 z1 \. g0 g: t; B, b0 q
- <form method="post" id="order">& W. N6 T% ~1 r Z
- Sort reviews by:' ~# ?7 ] ^" k# I
- <select name="select" onchange='this.form.submit()'>
( A4 a6 Q6 Y% g6 F6 T9 D - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>5 Z8 @9 m$ X& ]& Q
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>' W6 p3 v$ R; j) a: ~3 f; L1 p
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
" i1 Z) I) P6 b. X' j; q4 t% a3 S6 h+ n - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option> F8 L+ p: ?8 d& u) L& t- ?
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>5 D! R+ V4 t" I
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
5 ^1 |! }. t4 W. p - </select>
3 ^4 j0 O+ {! E* `6 \$ E4 B - </form>/ s) F3 }, f/ {4 e& Q8 F6 D4 e3 m
- . f7 k4 L- {* V6 R) L3 @
- <?php query_posts($query_string . $order); ?>* E& d' K7 l( l7 Q
- <?php if ( have_posts() ) : ?>
: w" w( h) W9 ^" N; E - <?php while (have_posts()) : the_post(); ?>
複製代碼 |