本帖最後由 pootor 於 2013-5-19 20:16 編輯 - w$ Z& C4 h, D# a2 q. N
luguokankan 發表於 2013-5-19 20:00 % z, q( q6 l8 ^6 n
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
" a+ {6 Y- Q) k x2 u9 c3 L$ F& S% M" r4 ]3 ?2 G! v" @+ I
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
! g# o- H$ R0 q. \2 a2 x - $order = "&order=DESC";% J: d0 P) X R$ e
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }: V- l6 Z" A: u; g
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
7 H: C4 @# J' B) q& z - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
9 Y9 ~" D: |7 o* q, } - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
) S( v% F1 P* N5 G# f- S. m( E, Q - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
1 v$ e" z. I6 u! Q8 | - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }. g$ S3 A4 u5 b, {$ l
- ?>- \: [4 ?: @' A' o, t
- ! i* c) ?; @( h8 w0 |0 j
1 ~! z- W' Z9 u$ X! K- <form method="post" id="order">7 F8 l2 |0 ^/ z$ J3 d5 B
- Sort reviews by:
' }. O* z0 g6 z9 \( Y6 N' C7 d - <select name="select" onchange='this.form.submit()'>
" G- [3 `& c9 o+ z% S' [) {+ }0 s - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
7 Z: u$ B" l- v4 L6 s# x& f - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>/ C' f# l p' }# E
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>7 {( _1 n/ p% v* z8 O1 z
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>/ \ N1 F! H. \
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>2 t, e5 s& t0 ]( ?5 H! e; P# V+ x0 E
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
9 M7 S t8 k2 A' x( ^ H) j7 _; l# Y - </select>' z' z7 e+ Z4 F
- </form>0 r: ` P& s2 L$ {( R
$ _3 ?/ `) E: ^1 g- <?php query_posts($query_string . $order); ?>
$ \) ?+ x/ m- j1 |$ e - <?php if ( have_posts() ) : ?>
' \1 R! w" S8 `, r6 M - <?php while (have_posts()) : the_post(); ?>
複製代碼 |