Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
general-topic
sorting topics from A to Z
Avatar
Ben Strice
Rookie
Free Members
sp_UserOfflineSmall Offline
Jun 6, 2012 - 8:27 am

hi, 

Is it possible to sort the topics in an alphabetical order?

If so, can it be for just a specific forum and not all of them?

i know it has probably something to do with sp_loop_topics() but i don't know what exactly.

Thanks

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Jun 6, 2012 - 9:31 am

Yes it is possible but you would have to do this a long time before the topic loop. In fact you would need to apply this to the data query. This can be done via a filter hook.

it is important to just point out what the sort (order by) currently is because you would be overriding that. By default the order is:

topic_pinned DESC, spf_sftopics.post_id DESC

This means the list is sorted by the most recent post to the topic placing recently updated topics first. It also ensures that any pinned topics are set to the top. Further, if you use post moderation then this might be different for members and guests who would not be allowed to see these posts. So it can start to get complex.

However - knowing that and if you wanted to do this, then adding the following code to your spFunctions.php file (in your SP theme templates folder) will do the trick:

add_filter('sph_forumview_query', 'topic_by_name');
function topic_by_name($q) {
    global $sfvars;
    if($sfvars['forumid'] == XX) {
        $q->orderby = 'spf_sftopics.topic_name ASC';
    }
    return $q;
}

Of course you will need to change the XX for the forum id you want this to work for. Any pinned topics will not be at the top and any posts in moderation will show up in the last post column (although not the post content).

As always we recommend that you create your own SP theme so that any customisation is not lost during a future update. (http://codex.simple-press.com/codex/themes/theme-basics/creating-a-theme/)

andy-signature.png
YELLOW
SWORDFISH
Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Jun 10, 2012 - 5:24 am

Did you try this by any chance? I would welcome some feedback on whether this worked for you or not...

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 620
Members: 17365
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10128
Posts: 79626