本帖最後由 pootor 於 2013-5-19 20:16 編輯 . @8 d( R0 g; i0 w% `) U
luguokankan 發表於 2013-5-19 20:00 6 ~$ Z5 J* s' o& y( F% Y; Y; `
你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。- V7 O& m+ R( e* v
8 p5 _! e# f9 G9 ~4 b不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
. H0 P2 h7 w0 k s. d4 `; v) ~# T - $order = "&order=DESC";
" {! o' D, d, [0 \* R - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }! k; g' B1 ]: ?
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }+ R# ^9 U/ o6 t* B
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }( ~$ |; x! \: a' x* J" v
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }6 P2 h+ ]1 U6 u7 t0 i8 _1 |2 ~
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }; t$ V' m! e* Z; ?
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }5 a) v: l) i7 G, L) q
- ?># P& b0 R8 Q1 P! {# A6 s
- 0 g( H/ B) H! v
' T* d# d. T$ G# M9 D: u! e- <form method="post" id="order">4 W$ h* @8 A( }4 [6 @
- Sort reviews by:
: R* n1 D' M3 m8 N - <select name="select" onchange='this.form.submit()'>
5 W7 P/ ^4 C7 m, [ - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
" r# M! [2 o# {! v- J - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>" D* \) t0 C% W0 J, @ }
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
- [/ { o6 t& S& v( F9 G' g) Y - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>) q- u$ p) u$ E O, g
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>1 e4 a# B+ q' K- E1 S
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
9 F7 S A& @% J. L% d" a - </select>) s4 E. P$ j6 u
- </form>- T( e }8 Y2 Z/ z& h5 O* M/ d
8 j* K1 e' n$ q% K* E+ J- <?php query_posts($query_string . $order); ?># M! x- G: A `" Z6 C
- <?php if ( have_posts() ) : ?>
$ c6 O# [" P# d# c - <?php while (have_posts()) : the_post(); ?>
複製代碼 |