本帖最後由 pootor 於 2013-5-19 20:16 編輯
9 ~( S* y% i- H7 _2 w, Iluguokankan 發表於 2013-5-19 20:00 
3 r1 ]# v6 R; k% T你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。 |/ ?: ]/ C) {# \. O
% }. p0 U ^. M4 X) H1 _: x不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
7 _" I+ p* O, u: Q - $order = "&order=DESC";
$ o. p5 I4 I$ V8 o5 A/ e2 o - if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }5 i# H- J1 y3 j L4 a
- if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }
/ {) c/ D- X7 |' n+ Z4 j/ H" r - if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
; V- Z; J' M% K( _+ P8 q* Q - if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }. A1 w* N# \! E' j6 _
- if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }5 o& O2 M1 x' @4 c3 ?! w; Z; D
- if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
$ v* x/ {% L, X% v1 o - ?>
' k# b! C0 c E; u; h - 2 g0 l- a: @+ E
+ V( M. K8 s! q0 `6 \1 A+ P1 h- <form method="post" id="order">
% W2 ~% z5 e4 W# S' h - Sort reviews by:- L6 @5 _3 B3 ?/ K% t
- <select name="select" onchange='this.form.submit()'>2 X$ K$ Y" U) E* x, C0 b) j2 I
- <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
; r" y6 `) B' ]2 T/ V - <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>! H2 o9 l3 O' m: o
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>- q% m9 y' s! o& G1 `3 c3 y! e' }# K
- <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>4 u# J, A0 A% M# n) A
- <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>0 ^- k' R9 O* }1 B b. C4 X
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
o# s$ f9 b* C - </select>
% B" l0 B3 e7 t - </form>" q1 p2 w% [# A2 d9 R9 B
- - h7 v" P3 z p$ q$ I/ J k# l
- <?php query_posts($query_string . $order); ?>+ l9 l+ D1 E1 S. k
- <?php if ( have_posts() ) : ?>
! n1 A7 n6 }, M" m! X; ? c - <?php while (have_posts()) : the_post(); ?>
複製代碼 |