記事をID順にソートして表示する

提供: GeeklogJpWiki

記事を日付昇順に表示する

public_html/index.php の199行目:

msql['mysql']="SELECT STRAIGHT_JOIN s.*, UNIX_TIMESTAMP(s.date) AS day, "
         . $userfields . ", t.topic, t.imageurl "
         . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, "
         . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid) AND"
         . $sql . "ORDER BY featured DESC, date DESC LIMIT $offset, $limit";

修正前:

ORDER BY featured DESC, date DESC 

修正後:

ORDER BY featured ASC, date ASC

この方法と話題における 1ページあたりの記事数 に負数を使うことで、話題によって記事の並びを日付降順(標準)と日付昇順を選ぶことが出来ます

public_html/index.php の $topiclimit を取り出している(1.4.1だと108行目 1.5.0だと187行目)

    $topiclimit = DB_getItem ($_TABLES['topics'], 'limitnews',
                              "tid = '{$topic}'");

の後に

    $sortthis = 0;
    if ($topiclimit < 0) {
        $sortthis = 1;
        $topiclimit = -$topiclimit;
    }

を追加

上記sql文の修正部分を

---1.4.1の場合---

if ($sortthis == 0) {
    $msql['mysql']="SELECT STRAIGHT_JOIN s.*, UNIX_TIMESTAMP(s.date) AS day, "
         . $userfields . ", t.topic, t.imageurl "
         . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, "
         . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid) AND"
         . $sql . "ORDER BY featured DESC, date DESC LIMIT $offset, $limit";
    } else {
    $msql['mysql']="SELECT STRAIGHT_JOIN s.*, UNIX_TIMESTAMP(s.date) AS day, "
         . $userfields . ", t.topic, t.imageurl "
         . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, "
         . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid) AND"
         . $sql . "ORDER BY featured ASC, date ASC LIMIT $offset, $limit";
    }

---1.5.0の場合---(1.5.0だと285行目)

if ($sortthis == 0) {
    $msql['mysql']="SELECT STRAIGHT_JOIN s.*, UNIX_TIMESTAMP(s.date) AS unixdate, "
         . 'UNIX_TIMESTAMP(s.expire) as expireunix, '
         . $userfields . ", t.topic, t.imageurl "
         . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, "
         . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid) AND"
         . $sql . "ORDER BY featured DESC, date DESC LIMIT $offset, $limit";
} else {
    $msql['mysql']="SELECT STRAIGHT_JOIN s.*, UNIX_TIMESTAMP(s.date) AS unixdate, "
         . 'UNIX_TIMESTAMP(s.expire) as expireunix, '
         . $userfields . ", t.topic, t.imageurl "
         . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, "
         . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid) AND"
         . $sql . "ORDER BY featured ASC, date ASC LIMIT $offset, $limit";
}

に変更

1ページあたりの記事数に例えば -5 を入力すると記事表示数は5で日付は古い順に表示されます

注目記事の取り扱いを考えると ORDER BY featured DESC が良いように思います

date の代わりに sid を使えば、記事IDでのソートが可能です

記事をID昇順に表示する

この項目は書きかけです。

個人用ツール