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 in One Forum by Post Date
Avatar
Duston
Member
sp_UserOfflineSmall Offline
Nov 22, 2013 - 8:58 pm

I'm curious if there's a way to sort the order of the topics in only one of our forums by the date they were posted instead of by which topic has the most recent post.

Looking through the WIKI here, it seems this was an option at one point or another:
http://wiki.simple-press.com/a.....-settings/

Our forum is used for classified ads so we only want new listings to appear as the most recent to our members.

Thanks!

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Nov 23, 2013 - 1:16 am

yes... on the forum view, use the forum tools and select reverse sort this forum...

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Nov 23, 2013 - 4:23 am

I suspect what Steve is suggesting wont give you quite what you want either. That option will reverse sort and keep the oldest topics at the top but it will still sort the newest according to which ones have received a post - just at the end.

If, by the question, you literally meant in the order that the topic (i.e., first post) was created then this can be done but it needs a small piece of code to run against the database query using one of our filter hooks. In this case the 'sph_forumview_query' filter. From this you can adjust the sort order.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Duston
Member
sp_UserOfflineSmall Offline
Nov 24, 2013 - 3:15 pm

Yellow Swordfish said
If, by the question, you literally meant in the order that the topic (i.e., first post) was created then this can be done but it needs a small piece of code to run against the database query using one of our filter hooks. In this case the 'sph_forumview_query' filter. From this you can adjust the sort order.

Yes, that's exactly what I mean. I've never used your filter hooks but am somewhat familiar with Wordpress hooks in general as well as PHP. Is there a "how-to guide" somewhere explaining how to use your filters and what code would I need to use to be able to achieve this topic order?

Thanks!

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Nov 24, 2013 - 4:46 pm

our filters work identically to wp filters...  use the filter Andy referenced and replace the sort order...

this is the filter usage:

        $spdb = apply_filters('sph_forumview_query', $spdb, $this);

take a look at the $spdb object that is passed...  you will want to update $spdb->orderby element to what you want...  for reference, $this will contain the forum view class object...

Avatar
Duston
Member
sp_UserOfflineSmall Offline
Nov 26, 2013 - 8:04 am

Ok, I guess I don't know as much as I though about filters. I have no clue what to do here. I only want one of my forums to be sorted this way. What code do I need and where do I put that code (functions.php??)?

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Nov 26, 2013 - 10:05 am

This one is actually pretty simple... We would suggest that you put the code in the forum theme template file spFunctions.php... Try this:

add_filter( 'sph_forumview_query', 'my_filter', 1, 2 );
function my_filter( $db, $forum ) {
    if ( $forum->forumId == XX ) {
        $db->orderby = 'topic_id ASC';
    }
    return $db;
}

Basically copy and paste this exactly as it is. Of course you can change the function name if desired!

Firstly replace the XX with the ID of the forum you wish to change the sort order of. You can find that in the admin Manage Forums listing.

Now the normal, default order by instruction is:

ORDER BY topic_pinned DESC, spf_sftopics.post_id DESC

To change this to order by when the topic was created starting with the oldest then use the code given. If you want the newest first then change to

topic_id DESC

If you DO have some pinned topics and wish those to stay on top use:

ORDER BY topic_pinned DESC, topic_id ASC

And hopefully that will do the trick. Oh - one more thong...

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/.....g-a-theme/)

 

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: 619
Members: 17361
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10127
Posts: 79625