本帖最後由 pootor 於 2013-5-19 20:16 編輯 0 l, L4 R% i: M- L
luguokankan 發表於 2013-5-19 20:00 % w& e$ N* ` K
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
8 B$ [6 `) f3 L. o9 d, M+ x; D: {" p/ \( i- U$ r+ I6 {
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php2 P0 L, g* o7 s ~6 e: `% c
- $order = "&order=DESC";- `/ X1 j1 O; L3 v$ _
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }: N8 p$ }+ e# P1 y
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }' r& |9 L2 {. o2 E6 b+ S$ s
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
; u' E# `8 _7 N5 K! H% x% N! R8 B/ {: n - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
5 f- ~) P" w7 l - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }4 ]7 ], ~# X. ?; ?; V4 Q. N" D L3 o
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
4 p+ X j! L ~7 t - ?>
4 G9 f( M1 u8 t4 r - $ K! {% ~+ B& q" a3 W2 x
* y+ s+ i( V8 Q6 i6 a- <form method="post" id="order">
], t" N+ b3 K! i, _ - Sort reviews by:
3 R0 \; {( ~% Q+ V% { - <select name="select" onchange='this.form.submit()'>/ |( l4 X+ k0 F% e# I7 ^
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>& E7 z0 b# G" ~3 x
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>( b! T( i) E. c4 t' S5 _
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>/ r8 f7 t* t; K( \9 |8 q
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option> h, C4 U1 I( v3 E$ H
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
2 i: _+ `7 \9 O1 E7 b4 m+ Q4 k - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>: ~2 }- q" _7 w/ t3 s* ?
- </select># ^8 h! G" U! w. P4 E' l) B/ n
- </form>; F! x" u: C7 P8 k3 u
- 6 p5 F3 d8 |7 Z% y1 r
- <?php query_posts($query_string . $order); ?>
- T2 {3 B% g6 ]; L8 V- w9 I8 ~ - <?php if ( have_posts() ) : ?>( t. A- z0 X3 g& J. U) L
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |