Jump to the post that solved this thread.
Not Solved [How To?] Is there a way to sort forums alphabetically?
#1
Not Solved
I've had a little look online but cannot find a way to sort forums (not threads) alphabetically. Sure, I can change the order to be 1, 2, 3 and so on, but this could become inconvenient when adding, renaming and removing forums, which I will be doing frequently.

Is there an easy way to alphabetically sort these automatically?

My website is theswitch.club, if that matters. A little embarrassing to link to as it's nowhere near ready (thankfully, most issues are easy to solve on my own), but hey, that's what the bold bullet point under the red text said to do.
Reply
#2
Not Solved
Changing the order is the best and safest way to do this. It isn't that much of a pain when you remove/add/rename forums either. You could even split them up into multiples of 5/10 just incase you do
Reply
#3
Not Solved
You could probably set up a custom task to update the display order.
Reply
#4
Not Solved
(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?
Reply
#5
Not Solved
I really don't see why you would want to do that. It is a lot more simplier to just organise them yourself.
-Ben

Please do not PM me for support. I am looking to be hired for paid services.

You can view my paid services here.
Reply
#6
Not Solved
(2016-11-30, 09:11 PM)Ben Wrote: I really don't see why you would want to do that. It is a lot more simplier to just organise them yourself.
[Image: mylzvq.png]
I would have to agree with Ben. As shown above you are given numbers to determine the order. I would put your sections in alphabetical order in notepad or something then number everything based on your list. In my opinion you shouldn't update your sections so often that it becomes an issue to maintain the order if your prefered manner. That being said it is an opinion, not a fact, it's up to the individual administrators on how they run their forum.
Software Engineer specializing in C# Program Development
Reply
#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.


Forum Jump:


Users browsing this thread: 1 Guest(s)