本帖最後由 pootor 於 2013-5-19 20:16 編輯 $ o! M# I# P' k z# t
luguokankan 發表於 2013-5-19 20:00 
# ^ y; U$ H/ E- }! S2 M% Y2 a4 f$ U% c- R你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
0 h4 m5 H7 O0 s$ \' [8 E! p5 j0 w# {' X
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php4 ?/ m. D, A" Q( N0 Y1 D2 p7 v
- $order = "&order=DESC";# R! p/ @9 L$ F3 U; E( |
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
1 X2 d: w% P, u E6 J L/ l, E' h8 i' L - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }& r2 l* j& @7 H B4 J8 o
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
3 t/ G- O9 v/ Z, G7 H - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
+ f% F- s ~, I: {, v3 S& E. C! ? - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
; V! E* R+ I% q4 }/ Q0 \8 J+ z2 Z - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }/ g- {6 ^; E9 O/ K$ a7 P
- ?>, z: S. q& L6 o& B
- ' u+ f1 Y8 O( Y! f+ I
- ' \" T, [4 {& K( `, S7 j$ p
- <form method="post" id="order">6 w& S/ \7 M( m8 x2 M: w1 Z
- Sort reviews by:
( g. [' g2 d# y/ C6 E Y - <select name="select" onchange='this.form.submit()'>
; o$ P- I$ m9 z( r/ P; |# E- g, X/ \ - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
# L4 T* v: q; D1 M- j# w! O - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
, S% x( o3 x# y7 u" @( T- O - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>+ L* |/ G" x* x
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>( [$ @+ @9 W" U7 Y4 q8 s; v
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
! Y: p7 b- v- {9 z1 ?' \8 M0 y - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>; {# x# L; Q0 U, H, |$ s
- </select>. ?. m/ D f# \* ]: U, |$ p, N( q
- </form>/ S& r9 J5 x8 I/ U! l
& L. _, P3 g0 U# [( }- <?php query_posts($query_string . $order); ?># b/ l# q& U, a7 [$ T4 j2 T; O
- <?php if ( have_posts() ) : ?>2 [! k, u5 n: n6 t1 G; _9 ?
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |