Sort topics Alphabetically in a single forum?

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Anti-Spam Guide
User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Sort topics Alphabetically in a single forum?

Post by Volksdevil »

Hi all,

Im new to PHPBB, and i recently installed it through 123-reg, i have absolutely no experience with databases, but thankfully they took care of that.

Im looking for a way to sort a single forums posts in alphabetical order by default, it's a forum that will contain how to guides for vehicle modifications/jobs. I have searched and searched, but i keep finding dead links, and posts from years ago :cry:

This was very easy to do in invisionfree as it was simply an option when setting up the forum. I'm a little overwhelmed by the complexity of PHPBB as a newbie to be honest.

This mod would be for a new forum that i plan to set up.
Any simple and easy to understand help would be appreciated.
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

Jeroen B
Registered User
Posts: 1222
Joined: Wed Jul 02, 2008 6:23 pm
Location: The Netherlands
Name: Jeroen

Re: Sort topics Alphabetically in a single forum?

Post by Jeroen B »

If it's only for one single forum, you can try this:

Open: viewforum.php

Find:

Code: Select all

// Forum is passworded ... check whether access has been granted to this    
Add before:

Code: Select all

if ($forum_id == 2)
{
    $sort_by_text = array('t' => $user->lang['TOPIC_TITLE']);
    $sort_by_sql = array('t' => 't.topic_title');
    $sort_dir = 'a';
} 
[/b]

$forum_id == 2 is the forum ID of the forum which you want to sort alphabetically, so you can change that. Good luck :)
Jeroen • My modifications

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Sort topics Alphabetically in a single forum?

Post by Volksdevil »

Hi, that seems to sort of work thanks! :D

There is one topic starting 'W' which hasn't sorted correctly for some reason, it was previously an announcement, so i wonder if that is the reason? I have refreshed etc.
Last edited by Volksdevil on Sun Aug 26, 2012 3:26 pm, edited 1 time in total.
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Sort topics Alphabetically in a single forum?

Post by Volksdevil »

Hi, this dosn't actually work on my new forum which i needed it for.

Can anyone help please? :)
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Sort topics Alphabetically in a single forum?

Post by Volksdevil »

Can anyone help with this? Thanks. :)
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

trickoff
Registered User
Posts: 513
Joined: Mon Jan 07, 2008 12:23 am

Re: Sort topics Alphabetically in a single forum?

Post by trickoff »

This works perfect for me!
How should I write if I want it for several forums, this doesn't work:

Code: Select all

if ($forum_id == 27 or 24 or 29)
{
    $sort_by_text = array('t' => $user->lang['TOPIC_TITLE']);
    $sort_by_sql = array('t' => 't.topic_title');
    $sort_dir = 'a';
} 
edit: actually I found out that all this code does is to change post time from descending to Ascending, it doesn't sort the topics alphabetically

Jeroen B
Registered User
Posts: 1222
Joined: Wed Jul 02, 2008 6:23 pm
Location: The Netherlands
Name: Jeroen

Re: Sort topics Alphabetically in a single forum?

Post by Jeroen B »

Then this should work:

Code: Select all

if ($forum_id == 27 || 24 || 29)
{
    $sort_by_text = array('t' => $user->lang['TOPIC_TITLE']);
    $sort_by_sql = array('t' => 't.topic_title');
    $sort_dir = 'a';
} 
The || is the "or" operator :)
Jeroen • My modifications

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Sort topics Alphabetically in a single forum?

Post by Volksdevil »

It dosnt actually sort them alphabetically for some reason? :(
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

trickoff
Registered User
Posts: 513
Joined: Mon Jan 07, 2008 12:23 am

Re: Sort topics Alphabetically in a single forum?

Post by trickoff »

Pietje15 wrote:Then this should work:

Code: Select all

if ($forum_id == 27 || 24 || 29)
{
    $sort_by_text = array('t' => $user->lang['TOPIC_TITLE']);
    $sort_by_sql = array('t' => 't.topic_title');
    $sort_dir = 'a';
} 
The || is the "or" operator :)
Yes, I've tried that too, but with no luck.

And as Volksdevil says, this code doesn't sort the topics alphabetically

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Sort topics Alphabetically in a single forum?

Post by Volksdevil »

Hopefully someone can help us? :D

I really need it for a 'How to' guides forum, where there will be a lot of topics that need sorting a-z. I know there is a form at the bottom of each forum, but members never seem to notice things like that, and it would just look more tidy all sorted alphabetically by default.
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

Jeroen B
Registered User
Posts: 1222
Joined: Wed Jul 02, 2008 6:23 pm
Location: The Netherlands
Name: Jeroen

Re: Sort topics Alphabetically in a single forum?

Post by Jeroen B »

I think I solved te problem, I think it depends on the position of the code.
So try this (remove the old code):

Find:

Code: Select all

// Limit topics to certain time frame, obtain correct topic count  
Add before:

Code: Select all

// Sort topics alphabetically
if ($forum_id == 4)
{
    $sort_by_text = array('t' => $user->lang['TOPIC_TITLE']);
    $sort_by_sql = array('t' => 't.topic_title');
    $sort_dir = 'a';
} 
I think it should work when the code is at that place. Don't forget to remove the old code :)
Jeroen • My modifications

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51997
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Sort topics Alphabetically in a single forum?

Post by Brf »

Pietje15 wrote:Then this should work:

Code: Select all

if ($forum_id == 27 || 24 || 29)
{
    $sort_by_text = array('t' => $user->lang['TOPIC_TITLE']);
    $sort_by_sql = array('t' => 't.topic_title');
    $sort_dir = 'a';
} 
The || is the "or" operator :)
That is not how logical operators work. You would use:

Code: Select all

if ($forum_id == 27 || $forum_id == 24 || $forum_id == 29)

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Sort topics Alphabetically in a single forum?

Post by Volksdevil »

Seems to work with the new position :D
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

Jeroen B
Registered User
Posts: 1222
Joined: Wed Jul 02, 2008 6:23 pm
Location: The Netherlands
Name: Jeroen

Re: Sort topics Alphabetically in a single forum?

Post by Jeroen B »

Brf wrote:
Pietje15 wrote:Then this should work:

Code: Select all

if ($forum_id == 27 || 24 || 29)
{
    $sort_by_text = array('t' => $user->lang['TOPIC_TITLE']);
    $sort_by_sql = array('t' => 't.topic_title');
    $sort_dir = 'a';
} 
The || is the "or" operator :)
That is not how logical operators work. You would use:

Code: Select all

if ($forum_id == 27 || $forum_id == 24 || $forum_id == 29)
You're right! I didn't test it, thanks for this correction.
Jeroen • My modifications

trickoff
Registered User
Posts: 513
Joined: Mon Jan 07, 2008 12:23 am

Re: Sort topics Alphabetically in a single forum?

Post by trickoff »

Thanks, it works now =)

But is it possible to add support for UTF-8 characters?
Because all swedish letters like: å ä ö are displayed first in the order, but they are actually the last three letters in the swedish alphabet.

Locked

Return to “[3.0.x] MOD Requests”