本帖最後由 pootor 於 2013-5-19 20:16 編輯
# h* _ R8 ^6 p/ {luguokankan 發表於 2013-5-19 20:00 : S1 y; g; f1 F; ]
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。- `0 W7 h) |7 H) t; u0 J4 N/ l
( v# K( N7 n$ Z, x
不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php7 y; E i7 N1 v& e2 J
- $order = "&order=DESC";: l2 U( @2 k' V% L& q
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
: O. ?* w9 P$ ]3 U1 v: j - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
( ]- }+ q Q6 O$ U+ X - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
. t$ w1 ?! z6 c" F- j - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
6 Q# F B1 o2 L - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }7 @) T9 M( l. f# V& N
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }/ F- h) m [' W5 U# q
- ?># F( o% W, q8 }& @( o* Y
- 9 W& z7 R% ~1 p8 ~5 S9 E
- ! {( B7 x6 b o; ]% D: k" l$ i
- <form method="post" id="order">
; o9 Y, L' ^9 e2 i - Sort reviews by:
( }4 }* b5 o/ o n/ Q- P - <select name="select" onchange='this.form.submit()'>9 C8 K8 C. n5 d; @7 I
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>2 {0 T5 j# D1 A% }% J( u3 u) P
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
9 Q: x1 ?$ z; i' |! F! A - <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>/ h+ V- k1 i' U; s6 E) R% _
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
* Y9 s7 O) F8 F7 P% i6 U - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>+ i6 B4 f( b/ |& E, b
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>& b( z8 p( L; a0 @2 C
- </select>1 r7 m4 S, x% @" r7 Z5 p
- </form>0 u# `3 O/ z, m7 l }( t! p9 e
- 4 p' B, ?4 x: c3 Y1 @
- <?php query_posts($query_string . $order); ?>
3 `- p0 U6 N- I$ {& O - <?php if ( have_posts() ) : ?>1 K7 ~9 b1 |$ k) I" l9 l
- <?php while (have_posts()) : the_post(); ?>
複製代碼 |