Jump to the post that solved this thread.
Not Solved [How To?] Is there a way to sort forums alphabetically?
#7
Not Solved
(2016-11-29, 10:50 PM)The Switch Club Wrote:
(2016-11-29, 06:49 PM)laie_techie Wrote: You could probably set up a custom task to update the display order.

That looks like an interesting idea, and I can see how I'd add a task to the Task Manager, but I have no idea of what the PHP script would consist of. Is there any documentation for organising forums via a script?

I am at work and don't have time to test it, but the following is a good starting point:

Tasks are inside PHP files in the inc/tasks directory. Let's say you want to name this task Sort Forums. You'd create a file inc/tasks/sort_forums.php. The main method would be task_sort_forums($task).

This task would manipulate the mybb_forums table (please use the correct prefix). The relevant fields are fid (forum id), name, type (f=forum, c=category), parentlist (includes comma-delimited path, including this forum / category), and disporder.

function task_sort_forums($task) {
    global $db, $cache;

    $query = $db->simple_select("forums", "fid, name, type, substr(parentlist, 1, length(parentlist) - length(fid)) as parent, parentlist", '', array('order_by' => '4, 3, 2'));
    $count = 1;
    $old = '';
    while ($row = $db=>fetch_array($query)) {
        if ($row['parent'] != $old) {
            $count = 1;
            $old = $row['parent'];
        }
        $updated_record = array('disporder'=> $count);
        $db->update_query(
            'forums',
            $updated_record,
            'fid=' . intval($row['fid'])
        );
        $count++;
    }
    $db->free_result($query);
    $cache->update_forums();
}

You would then need to go into ACP => Tools & Maintenance => Task Manager in order to schedule this task.
Reply
Jump to the post that solved this thread.


Messages In This Thread
RE: Is there a way to sort forums alphabetically? - by laie_techie - 2016-12-01, 04:58 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)