change topic sort order

Discussion forum for MOD Writers regarding MOD Development.
Locked
Steamsheds
Registered User
Posts: 81
Joined: Sun Oct 17, 2010 2:18 pm

change topic sort order

Post by Steamsheds » Thu Oct 28, 2010 9:54 am

I need to change the order in which topics are listed in a forum.
First I am aware that the sort order can be changed at the bottom of the list. There is no default option that solves this problem -

I have a forum with over 1000 topics - the topics each have a unique `topic_title` and they were all entered through an external php program but not in alphabetical sequence. The date of the topics were all set to the board creation date (for internal reasons).

Some of the topics have subsequent reply posts.

Now when the topics are listed in the forum the default listing is in "Sort by Post Time Descending" sequence.

This unfortunately lists by last post time as the primary search index and what appears to be a random secondary index.

Is it possible to change this to sort by last post time as the primary search index and title as the secondary index. Either by changing the sql or by changing the table index?

User avatar
AmigoJack
Registered User
Posts: 5601
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: change topic sort order

Post by AmigoJack » Thu Oct 28, 2010 10:36 am

Open /viewforum.php and find these lines:

Code: Select all

$sql = 'SELECT t.topic_id
    FROM ' . TOPICS_TABLE . " t
    WHERE $sql_where
        AND t.topic_type IN (" . POST_NORMAL . ', ' . POST_STICKY . ")
        $sql_approved
        $sql_limit_time
    ORDER BY t.topic_type " . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order; 
Change only the last one of these lines into:

Code: Select all

    ORDER BY t.topic_type " . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order. ', t.topic_title';
Untested.
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.

Steamsheds
Registered User
Posts: 81
Joined: Sun Oct 17, 2010 2:18 pm

Re: change topic sort order

Post by Steamsheds » Thu Oct 28, 2010 11:01 am

So quick. So simple

Many thanks, you saved me time having to dig around in the code.

stewejazz
Registered User
Posts: 30
Joined: Tue Apr 16, 2013 10:19 pm

Re: change topic sort order

Post by stewejazz » Tue Jun 04, 2013 10:38 pm

Hi i have tried this code but i have an error.

Parse error: syntax error, unexpected T_STRING in /Applications/XAMPP/xamppfiles/htdocs/GREEN/viewforum.php on line 488

488 is the line where i paste your code.

pbrouwers
Registered User
Posts: 58
Joined: Wed Nov 11, 2009 11:07 am

Re: change topic sort order

Post by pbrouwers » Tue Jun 04, 2013 11:15 pm

You probably forgot the add the ; at the end.

User avatar
AmigoJack
Registered User
Posts: 5601
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: change topic sort order

Post by AmigoJack » Wed Jun 05, 2013 8:02 am

Don't confuse lines being displayed with actual lines - i.e. the following code is just one single line and just for display reasons you might see more than one now:

Code: Select all

    ORDER BY t.topic_type " . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order. ', t.topic_title';
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.

Locked

Return to “[3.0.x] MOD Writers Discussion”