本帖最後由 pootor 於 2013-5-19 20:16 編輯
) r& S1 a, P4 E7 ^luguokankan 發表於 2013-5-19 20:00 
. n* o) `+ k4 L0 f# T你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。9 q) P9 \ q% q% [
2 `* p8 ~ b& p j" b' }: ]不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
4 h0 `5 f8 h5 X9 b - $order = "&order=DESC";
+ K' x& K; h" ]1 V7 F- d* _# A - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }. Q) }7 P Z5 z h% v% M
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
, c* J. |% z! @2 a5 b+ z - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }, V) U! I$ r: u' z0 \
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
. J- W* m/ i; S5 Y - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
" T: O' I& y* X! ?% h$ c) j- ^7 B - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
+ ~- K( I8 w C( d2 b* j - ?>5 d) X3 S& M1 B O5 f8 T! P
/ v( ?8 W' A; t' d! U( z' y/ {
7 q6 f+ ^. L% [0 ^1 W( T- <form method="post" id="order">
& K" z2 A O) X - Sort reviews by:
3 e$ k3 A0 R/ T. t, y - <select name="select" onchange='this.form.submit()'>! z. T6 P6 y$ p
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
7 o# {2 S4 S; j9 T - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option> q" q4 C! ?; g. N3 u! `) C
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
( {4 _9 V; \; Z; T - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
" M3 w$ x# g0 W9 }6 H8 i0 s2 J - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
' @: J3 R$ K6 I+ H% ]$ o7 u) v - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>9 }- z0 `2 {& L& y
- </select>
. `6 [4 c0 M6 C# S8 B - </form>
- ]& h# ^; L& Z
) \) s3 H8 O# ^ ]0 ]- <?php query_posts($query_string . $order); ?>9 l0 j# y I% `1 L
- <?php if ( have_posts() ) : ?>% [% ]* h8 L! U& }
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |