Support Forum

Create Post Sort Order by Forum

30 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

Ok – well this following change has already been committed into core code so will be in the next SP update. The core file to edit is

/simple-press/sp-startup/forum/sp-forum-support-functions.php

The function you need to find is sp_populate_support_vars() around line 137

A few lines into that function you will find the line of code:

$sfvars['forumid'] = $record->forum_id;

Below this simply add:

$sfvars['groupid'] = $record->group_id;

Finally, in your SP theme functions file in the small sort routine, change the $sfvars[‘forumid’] to $sfvars[‘groupid’] along with the appropriate Group record number.

DO Dosenben
Dosenben
Member

Oh, best of both worlds! Much obliged! smile. I’ll implement as soon as iget around to it and report here if it worked as intended.

 

tankhs and best regards!

DO Dosenben
Dosenben
Member

Just did the test run on a single group, worked like a charm. Will add several over the next days; thanks again for the quick help! laugh

DH Dietmar Herian
Dietmar Herian
Member

Yellow Swordfish said
The quickest and easiest way to confine your sort change to a single forum would be:

add_filter('sph_forumview_query', 'my_sort_function');
function my_sort_function($sqlObj) {
    global $sfvars;
    if($sfvars['forumid'] == XX) {
        $sqlObj->orderby = SFTOPICS . '.topic_name ASC';
    }
    return $sqlObj;
}

Where XX is the forum ID you want to effect.

Hi SP-team,

I also do have some users who want to have influence in sorting posts preferably as  user profile option. Mainly, it is reverse sorting by date – oldest first. I could use the code sample with variation of sorting parameter Is there any document describing this? And how can I find out the forum ID?

YS Yellow Swordfish
Yellow Swordfish
Member

Not documented as such – no. But for posts, a similar type approach could be made. The filter to use would be ‘sph_topicview_query’ and the sql query would be against the SFPOSTS table using the post_id as the sort column.

You can find the forum ID in the forum listing in the forum admin.

Not sure how you would make it a user option though. Although you may be able to do this with a custom profile field.

DH Dietmar Herian
Dietmar Herian
Member

Yes, this would be the way to do it. I’ll make it a radio button.

After browsing through forum and documents, I only found this explaining how to read user profile data by programm.

I assume that this is outdated for V5.

What is the V5 name of the function ? Did not find anything searching for ‘sp_profile_get_data’ or similar.

I guess the array is similar ? Anyhow, if I knew the function, I can get it printed via wp_mail.

YS Yellow Swordfish
Yellow Swordfish
Member

Yes the old wiki only goes up to V4 I am afraid.

So – are you after the user data? If you go to the forum admin > Toolbox > Data Inspector and turn on the option to display spThisUser it will display it for you when you run the forum. You will be the only user to get this display. This will show you the data object available for the current user. It will include any custom profile fields.

DH Dietmar Herian
Dietmar Herian
Member

Sorry, I was not clear enough :

I am after the replacement for the function

$profile = sfc_get_profile_data( $userid )

What is the new name for V5? I need it for my php code.

Thanks for the hint to the data inspector. I will need it, too.

YS Yellow Swordfish
Yellow Swordfish
Member

There is no function. For the current user you simply globalise the $spThisUser object and use that. If it is not the current user you want you best tell me and I can point you in the right direction.

MP Mr Papa
Mr Papa
Member

if you want to specify the user, it would be:

    $thisUser = sp_get_user($userid);

where $userid contained the user id of the user…  if you are on a profile page, you could try:

        sp_SetupUserProfileData($userid);

which would actually populate the global variable $spProfileUser…

DH Dietmar Herian
Dietmar Herian
Member

Thanks a lot guys for your really excellent support.

I have implemented it now as a custom profile checkbox field where user can individually choose to sort posts in ‘reverse’ order – meaning oldest post first. And it works like a charm!

Hope they are happy now! Well, at least for a while!

Here is my piece of code in spFunctions.php of my SP-Theme:

function my_sort_function($sqlObj) {
        global $sfvars, $spThisUser;
//        $test = $spThisUser->sortierealtestenpostnachoben;       
    if($spThisUser->sortierealtestenpostnachoben) {
            $sqlObj->orderby = SFPOSTS . '.post_date ASC';
        }
        return $sqlObj;
    }

where ‘sortierealtestenpostnachoben’ is the slug name of the custom profile checkbox.

YS Yellow Swordfish
Yellow Swordfish
Member

I am impressed!

You are clearly one of the rare users who seems to have the posts sorted with the most recent at the top. I am afraid I am with your users on that one – I prefer the oldest first….

DH Dietmar Herian
Dietmar Herian
Member

Well, we have around 225 users in our small community of which 3 have requested to sort the ‘oldest on top’ way.

Seems that ‘most recent on top’ is kinda German standard (because of scrolling reasons) and it is the same in many other blogs I know and use.

Ok, ok, we also drive on the right hand side of the road – strange enough! :) 

De gustibus et coloribus non est disputandum!