本帖最後由 pootor 於 2013-5-19 20:16 編輯  
- p5 o/ Q/ K! |, Hluguokankan 發表於 2013-5-19 20:00  4 t' Z8 W6 Q/ l/ u  a% `$ [4 f# c  v* | 
你的問題是不是不會搞包含sort參數的 pagination?  加sort參數的分頁可以搞定。* [  c$ C9 E7 p: {* Q" w 
" h% v* J; N% l! N) a+ V1 n 
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php# m4 t2 o, k0 o2 M
 
 -   $order = "&order=DESC";' I$ P6 ^5 g1 }- a5 o7 x
 
 -   if ($_POST['select'] == 'tag') { $order = "&tag=mytag";  }
 
5 L, p6 V( n+ X9 w; B -   if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title";  }' p" Q: r+ U& \7 c" d5 W
 
 -   if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
 
7 G3 @. J+ o& ]5 L7 M6 Q4 U! J6 _* j2 o -   if ($_POST['select'] == 'oldest') { $order = "&order=ASC";  }3 ^8 Z5 B6 G: A  q6 k
 
 -   if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count";  }+ z+ P3 _5 Q2 \3 u1 I
 
 -   if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count";  }
 
5 R: V/ g( X, i8 T& g0 d - ?>
 
5 c) n6 N4 V3 n0 {# R  
7 o$ {' W; `0 k! ~- , h& B2 j" F* u' y( T
 
 - <form method="post" id="order">. b  d+ B4 b) |$ S( Q8 [* C
 
 -   Sort reviews by:
 
2 L0 c' c& R- T( O -   <select name="select" onchange='this.form.submit()'>
 
4 l# M' ~' G7 {5 m% o -     <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
 
: a. u/ S  h6 l4 A -     <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>- j; ~" a5 r0 Z: m
 
 -     <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
 
+ E5 k4 ?: v: }. a( `8 w -     <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>2 I* |. [1 N$ `) Y* A; K" S
 
 -     <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>" W( V& i! i$ Q& p
 
 -     <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>! I/ _6 W  R. u+ m
 
 -   </select>
 
1 o, _3 N* A( e  R' l9 E - </form>
 
5 X) @4 ]3 s" p) }! v  F  
7 Y* y1 B: {9 D2 H0 ^1 d- <?php query_posts($query_string . $order); ?>
 
9 A* c0 U+ W. J2 ~ - <?php if ( have_posts() ) : ?>5 E/ G6 Q( [2 s8 M. x
 
 - <?php while (have_posts()) : the_post(); ?>
 
  複製代碼 |