本帖最後由 pootor 於 2013-5-19 20:16 編輯
9 @9 J% H; L; Dluguokankan 發表於 2013-5-19 20:00 
+ R. { f; n7 u& Z; V你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
& s/ Q, @# K8 W6 `2 M/ Z8 f- {: z2 I( Q, Z
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
' W" C% x2 ]# x2 L- g0 T& d - $order = "&order=DESC";
' [: A* m' U/ `8 G5 ~! R4 z2 r; a - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
' K' c+ n2 `+ i - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }: `% f9 f+ U! L: t7 y
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
y: K, w( ?$ J# a0 V) U: a# F, [* Y - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
2 l6 d! @4 b7 W9 d% V$ B3 p8 _ - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }+ ^: x5 M% V; o' U7 C; P
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }3 z9 ~0 T1 H! d: U* H# k9 {' h/ A1 F
- ?>
8 R+ x: j' i3 P5 {% j# M& ~ - / R b( {: z, }) t- m
! B0 y4 u0 n9 J/ L( t* h# A- <form method="post" id="order">
5 L6 A! S7 C1 J' n1 S# A - Sort reviews by:4 O2 P, S! q1 J1 r
- <select name="select" onchange='this.form.submit()'>
% I6 `8 D- h2 r/ q8 e9 H8 J - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>: w* {1 [6 [$ y N- v, B& i `
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
0 f/ `' n/ H4 C - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>7 e6 j. ~7 m; w) Q B8 M
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
* P" C4 G& D) [/ D1 f7 B - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
Y5 p, Q" t0 ^* K0 `: e- M6 z" c - <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option># P% I$ F5 @9 m
- </select>3 n* C5 x- e3 n- X. t a8 y1 F7 M
- </form>
' a$ A% ~1 ]( F& Z n - 4 I$ u/ X6 o3 N
- <?php query_posts($query_string . $order); ?>: m* R% q, C5 Y$ F9 c: C2 i
- <?php if ( have_posts() ) : ?>
7 f3 ~8 b4 X) L: F$ } - <?php while (have_posts()) : the_post(); ?>
複製代碼 |