Skip to:
Content
Pages
Categories
Search
Top
Bottom

Sort Groups Alphabetically by default (BP 1.2)

  • Avatar of sawyerh
    SawyerH
    Participant

    @sawyerh

    I want the default sorting method of my groups to be Alphabetical instead of Last Active. Any ideas on how I would go about doing this? I’m using BP 1.2 RC2

    Thanks!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Avatar of Dwenaus
    Dwenaus
    Participant

    @dwenaus

    Here is a way to kind of do it

    in the main plugins folder add this to a custom-code.php file

    function custom_group_alpha_first() {
    ?><option SELECTED value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ) ?></option><?php
    }

    It will work, but then you have duplicate Alphabetic selects. You can try to hide the other one with CSS or Javascript using the DOM. good luck.

    Avatar of Dwenaus
    Dwenaus
    Participant

    @dwenaus

    you could also override this page in the buddypress folder using a child theme (I think):

    /bp-themes/bp-default/groups/index.php

    more info here:

    http://codex.buddypress.org/how-to-guides/building-a-buddypress-child-theme/

    but this is not very elegant, as future default theme changes for this file won’t come through

    Avatar of sawyerh
    SawyerH
    Participant

    @sawyerh

    Dwenaus, I tried your first method of creating a custom-code.php file and placing it in the wp-content/plugins folder, however it didn’t seem to work. Any other ideas besides the child theme?

    Avatar of dpolant
    dpolant
    Participant

    @dpolant

    I believe the correct way to do this is simply to go into the template file and rearrange the order of the <select> options so that ‘Alphabetical’ is first. ajax.php has functions that allow this to work.

    for my-groups, the correct template is bp-themes/bp-default/members/single/groups.php

    for the groups directory, bp-themes/bp-default/groups/index.php

    Avatar of sawyerh
    SawyerH
    Participant

    @sawyerh

    @dpolant, still doesn’t work. It does move the Alphabetical option to the top, however it doesn’t actually cause any re-ordering.

    Avatar of sawyerh
    SawyerH
    Participant

    @sawyerh

    Any other ideas? Thanks.

    Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    I think Dwenaus’s solution works, but he forgot a line:

    function custom_group_alpha_first() {
    ?><option SELECTED value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ) ?></option><?php
    }
    add_action( 'bp_members_directory_order_options', 'custom_group_alpha_first' );

    Another, less good, solution: Put the following in your theme’s functions.php:

    function members_alpha_by_default( $query_string ) {
    global $bp;

    if ( $bp->current_component == BP_MEMBERS_SLUG && !$bp->current_action)
    $query_string = 'type=alphabetical&action=alphabetical';

    return $query_string;
    }
    add_filter( 'bp_dtheme_ajax_querystring', 'members_alpha_by_default' );

    It’s not as good because it doesn’t change what the dropdown reads. A simple fix for that is just to move the Alphabetical option to the top of the list in your theme file, but if you’re going to do that you might as well just add SELECTED to the alphabetical option and skip the filtering function. Maybe I’m missing something with the bp_dtheme_ajax_querystring hook – is there a way to change what the dropdown reads? I thought that’s what ‘action’ was.

    Avatar of Pisanojm
    Pisanojm
    Participant

    @pisanojm

    @boonebgorges your “less” good solution is the best in my opinion… rather than add to the theme’s function just put in in bp-custom.php best of “both” worlds… (don’t forget to change order of drop-down as Boone suggests in the theme)….

    Avatar of Pisanojm
    Pisanojm
    Participant

    @pisanojm

    Important to note if you want to use @boonebgorges code with “GROUPS” and not “MEMBERS” sorting -you will have to change to the GROUPS slug… use this:

    `function groups_alpha_by_default( $query_string ) {
    global $bp;

    if ( $bp->current_component == BP_GROUPS_SLUG && !$bp->current_action)
    $query_string = ‘type=alphabetical&action=alphabetical’;

    return $query_string;
    }
    add_filter( ‘bp_dtheme_ajax_querystring’, ‘groups_alpha_by_default’ );`

    Avatar of Andrew Tegenkamp
    Andrew Tegenkamp
    Participant

    @andrewteg

    Old thread but good google result… this mod seems to work best for me

    1) add selected to your theme/child theme and also put Alphabetical at the top.
    2) add this function into your theme’s functions.php
    `
    function sort_alpha_by_default( $qs ) {
    return ($qs) ? $qs : ‘type=alphabetical&action=alphabetical’;
    }
    add_filter( ‘bp_dtheme_ajax_querystring’, ‘sort_alpha_by_default’ );
    `

    Avatar of Andrew Tegenkamp
    Andrew Tegenkamp
    Participant

    @andrewteg

    I forgot to check for just members/groups so here’s the corrected version…

    `
    function sort_alpha_by_default( $qs ) {
    global $bp;
    if (!$qs && ( $bp->current_component == BP_GROUPS_SLUG || $bp->current_component == BP_MEMBERS_SLUG ) )
    $qs = ‘type=alphabetical&action=alphabetical’;
    return $qs;
    }
    add_filter( ‘bp_dtheme_ajax_querystring’, ‘sort_alpha_by_default’ );
    `

    Avatar of skeltonmedia
    skeltonmedia
    Member

    @skeltonmedia

    Excellent guide, very helpful.

    Is there anyway to extend the function to sort alphabetically by last name?

Viewing 12 replies - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.