本帖最後由 pootor 於 2013-5-19 20:16 編輯
( M4 S' O7 [8 q* mluguokankan 發表於 2013-5-19 20:00 
" W9 ], ] A3 l- u2 {1 H3 Z: ]/ U* q你的問題是不是不會搞包含sort參數的 pagination? 加sort參數的分頁可以搞定。
: J* \& y$ z* M1 ^8 x' a( {
/ ]0 o( s3 v- j( g% c0 B5 k* ?不能搞定:不加參數,可以實現用下拉列表實現訪客排序,但是排序不能分頁,訪問第二頁排序就失去作用了。能否解決分頁也能排序(不加參數)?下面的代碼可以實現排序,但不能分頁。- <?php
) _7 i* ^+ Y- y, d( p8 A - $order = "&order=DESC";8 }7 z4 N0 x2 Z1 r" L8 g
- if ($_POST['select'] == 'tag') { $order = "&tag=mytag"; }
! x1 s3 e1 H! A1 Y3 B - if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title"; }& z3 E2 c7 e. _ Z, ]% @5 j
- if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }0 ], _ C7 P4 n# |7 I/ b& U
- if ($_POST['select'] == 'oldest') { $order = "&order=ASC"; }
' m- D2 O. \3 ~# p# v9 H - if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count"; }
& C* T' f6 i0 b* j - if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count"; }
( ]8 u3 r+ N$ X# [' g2 W Z - ?>+ U2 t' z+ S& L
# b! _& }+ {* B5 W M) N# W+ a/ [) Y; ^$ [
* q8 l6 S7 B }1 M& |* \- <form method="post" id="order">4 j) f, b+ j& }# H5 y" N6 Y
- Sort reviews by:* j% @6 m. _$ X: v7 C" J, N* u, f
- <select name="select" onchange='this.form.submit()'>
, k. b- Y9 } p* Q5 A - <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>4 N$ h8 r/ h- [
- <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>: p* U* o* @5 I% Y @
- <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
' G. m+ K& f2 d* ] - <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
: d2 e/ f* `. X4 L+ M! s! Q: | - <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>, U- M3 e, M4 @! A+ N7 p
- <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
0 C5 V- R' K3 B% h/ V/ w9 b - </select>: O+ a( U7 a7 _
- </form> O( }) Z6 G7 _* C
3 V" W3 W- x* M3 \/ Y- <?php query_posts($query_string . $order); ?>2 B* Z, v7 p0 y* v2 X R
- <?php if ( have_posts() ) : ?>
3 A z7 B' F0 S' m3 G - <?php while (have_posts()) : the_post(); ?>
複製代碼 |