本帖最後由 pootor 於 2013-5-19 20:16 編輯 1 K% C) N3 Y7 ?9 a% w
luguokankan 發表於 2013-5-19 20:00 
; p0 R2 ]# w9 F' p4 c9 I+ h6 j5 |/ I你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。1 F4 ]4 l( j+ H% i/ i2 @
2 E& Q' K! Z) e4 J不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
, f* ], U, Y: a. U9 X - $order = "&order=DESC";
" r5 O' s7 i$ J4 ?" ~ - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }2 v! P) k8 A+ L) Z
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
' d' K( R1 b4 y" n0 L5 `4 h8 B - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
' L* |5 Y7 @) G' ^1 a0 b - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
( u( _% [* b5 r8 @( d - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
3 ^$ g6 Z. I# l4 E* k8 d8 T - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }; n# R9 E' t+ }. J6 U/ H/ ]
- ?>
3 D* c, @& ?1 e- g: T - 1 l$ |6 ^' U, r) { h+ s% H' I
* p% R+ L( t, [3 O: j2 V- <form method="post" id="order">
& P) }1 h& X k5 U - Sort reviews by:
: d" o0 U. p4 v( X$ z0 k# U - <select name="select" onchange='this.form.submit()'>. ]) d% n; E: y/ }* g# _
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>8 u" K3 H- N0 d7 o: [' K( L
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
5 t5 W! y4 I3 d, t" C& _ - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>; _9 h, N9 ~+ g- }- t5 W9 [
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>2 C) R) H: J! i! h% Y
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
M9 d6 {* R2 B - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>+ T5 \/ v5 f/ w5 G
- </select>5 P4 z3 ^4 H/ h2 }# H3 u5 m
- </form>% C- I. o1 v% p" W) r2 S- r5 w9 v8 B
5 v, h; B5 y( j5 V u3 ~/ m% c0 r& J- <?php query_posts($query_string . $order); ?># x* ~7 A& K: T2 ~8 |
- <?php if ( have_posts() ) : ?>
2 a; w/ D1 M* x/ ^3 _ c - <?php while (have_posts()) : the_post(); ?>
複製代碼 |