In my forum the default sort order is by most recent reply. I would prefer it be most recently posted topic. I have tried a few things in the forum.module and forum.pages.inc but have not determined the correct tweak yet. This would seem an easy thing to change. Is it?

Comments

vm’s picture

create a new view with the views.module

shr1k3’s picture

i don't know how to use views.module yet but will look into it. thx

vm’s picture

There is a videocast floating around that shows how to accomplish this. I've tried locating it but alas, could not find it. you may have better luck.

dnewkerk’s picture

You might be able (I don't know) to affect the sorting order of the topics using db_rewrite_sql(). You would include the modification in a small personal module. If not, skimming in forum.module I see some things such as function _forum_get_topic_order_sql($sortby)... which would be a good place to start looking. In any case do not modify forum.module (unless you are prepared to track and adapt your changes with each upgrade). There are many hooks available and most likely some way of doing what you want cleanly through code in your own module.

-- David
davidnewkerk.com | absolutecross.com
View my Drupal lessons & guides

aharown07’s picture

I'd also like to fix this. Before I found this thread, posted in forums here http://drupal.org/node/512662

Since I have no experience in writing modules and barely an inkling on how php works, I don't really know what to do with function _forum_get_topic_order_sql($sortby)
It's amazing to me that there isn't already a module for this... it's especially odd to me that in Forum options you have a sort by Date option, but it doesn't actually sort by any date I've been able to identify. Always defaults to most recently commented.

aharown07’s picture

This works but, of course, I don't recommend hacking the core.
I'd be delighted to hear of a non-core-hack solution.
(BTW, how exactly would I go about getting this change into D7?)

Find function _forum_get_topic_order() in file modules/forum/forum.module
change l.last_comment_timestamp to n.created, so the final version looks like this:

  case 1:
    return array('field' => 'n.created', 'sort' => 'desc');
    break;
  case 2:
    return array('field' => 'n.created', 'sort' => 'asc');
    break;
michelle’s picture

You wouldn't get that literal change in core because 99% of folks out there want it to sort as it does now, by most recently commented with brand new topics at the top. You could add in your way as an extra option, but that would require changing the UI and adding another case. If you want to do that, file an issue against core forum. Preferably with a patch but you can put in a feature request if you aren't able to make the patch yourself.

Michelle

aharown07’s picture

The problem I'm having is that brand new topics are not sorting to the top... perhaps because it's looking at nid for that part of it? I don't know.
All I know is that scheduled nodes, when they go live, do not sort to the top, even though the created date on them shows as brand new.
But w/the hack, they do.

vm’s picture

has anyone checked administer -> forums -> settings ?

where sort order and such can be altered?

aharown07’s picture

Yes, been there. Doesn't produce expected results.

vm’s picture

if you did this after your hack, I wouldn't expect it to work.

michelle’s picture

On a normal forum, sorted to newest first, the order is like this:

Sticky
Nodes with no comments that are newer than the most recent comment
Nodes with recent comments, most recently commented on first

If yours isn't acting that way, then perhaps it's a bug with the scheduler module.

Your hack means that it will only go by the order the nodes were created and not bump nodes when they are commented on. If that works for you, great, but that won't work for most people who expect the forum to work normally.

Michelle

aharown07’s picture

As it happens, I am also having some other problems w/scheduler. Maybe that's really what's messed up here. The normal sort is certainly not what I'm seeing.
I have an issue open at Scheduler regarding custom content types don't appear in forum at all when they go live... on my site, their row in the forum table actually gets removed when they go live. Hitting Save again, gets them into the forum table agian.
Didn't think it was related since there is no visible impact on the Created date.

aharown07’s picture

The "scheduler problems" I referred to turned out to not be Scheduler. Rather there is a bug in the node_api in Forum that affects Scheduler.
Info on that here: http://drupal.org/node/511070

Meanwhile, scheduled posts are still sorting funny but only the older ones (before the forum.module patch referred to in 511070). So I'm using the sort hack for probably about a week until the older nodes are not so 'looked for'... then it goes back to how it was.