Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Trying to modify the group loop


  • vonWolfehaus
    Member

    @vonwolfehaus

    I understand how it works but I can’t figure out how to detect if the user clicked on “All Groups” or “My Groups”. I know it makes an ajax call and I see it in groups_loop (it calls bp_ajax_querystring)… but I don’t know how to get the info I need from it. How do I create a conditional so that I can display different groups depending on which tab they’re in?

    To be specific about my request, I’m looking to display a few groups in the “All Groups” tab, while only displaying hidden groups that the member is a part of in the “My Groups” tab. Any help regarding this kind of customization would be greatly appreciated!

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

  • vonWolfehaus
    Member

    @vonwolfehaus

    I need to solve this issue! Help please!

    I need to know how this line “ figures out if the user is looking at the “all groups” or “my groups” tab. I need to display different content based on this query: the “all groups” tab will display a static list of some groups, while the “my groups” tab will display only hidden groups that the user is a member of. But nowhere in the loop does it distinguish between the two tabs.

    Any ideas?


    Boone Gorges
    Keymaster

    @boonebgorges

    Check out the function bp_dtheme_ajax_querystring() in bp-themes/bp-default/_inc/ajax.php. That’s where most of the bp_ajax_querystring() magic is happening. Essentially, it looks first in the $_POST (for a new value via AJAX) and from there in the $_COOKIE for the current page view.


    vonWolfehaus
    Member

    @vonwolfehaus

    Thanks, but I have been staring at that code for a couple hours and I cannot decipher it–I don’t know very much about PHP. What exactly do I need to do to that function? How do I get the string I need in groups-loop.php to distinguish between the two group tabs? It returns a very complex value that I don’t even know how to access.


    vonWolfehaus
    Member

    @vonwolfehaus

    Alright, brute forced it. I just echo’d the query’s result and copied it into a conditional like this:
    `
    //do loop for “my groups”

    //do my own thing for “all groups”
    `

    Yet another case where I should just display the raw output and work from there. Tried to be “proper”. Proper fails :(


    Boone Gorges
    Keymaster

    @boonebgorges

    I think you might be barking up the wrong tree. Since you want to repurpose an existing query (the ‘my groups’ query) you don’t really need to alter the querystring. Instead, you should be altering the behavior of the query itself, which happens at the level of the bp_has_groups() function, as found in bp-groups/bp-groups-templatetags.php. One of the arguments for that function is user_id; when one is passed, you know you are looking at a my-groups loop.

    Ideally, you would be able to filter bp_has_groups() to detect when a my-groups-type query was being requested, and then hijack it and do a query just for hidden groups. Unfortunately, I don’t believe that there is going to be an easy way to do that in this version of BuddyPress. For one thing, while there is a filter on bp_has_groups, the original arguments (like user_id) are not passed along to the filter in BP 1.2.7 (it’d be a good enhancement request). Second, there is no way to filter groups by status (public, private, hidden) at the moment (that too would be a good enhancement request).

    One quick and dirty way to do something like what you want to do is to filter bp_has_groups, grab the content of the group query out of the groups_template global, and remove the ones that are *not* hidden. It’s not an ideal solution for a number of reasons (for one, it screws up pagination) but it can work. Here’s an example off the top of my head (untested!)

    `function bbg_hidden_groups_only( $has_groups ) {
    global $groups_template;

    // when we are looking at a my-groups page…
    if ( bp_is_user_groups() ) {
    foreach ( $groups_template->groups as $key => $group ) {
    if ( ‘hidden’ == $group->status ) {
    unset( $groups_template->groups[$key] );
    }
    }

    // reset the keys so you don’t end up with blank spaces
    $groups_template->groups = array_values( $groups_template->groups );
    }

    return $has_groups;
    }
    add_filter( ‘bp_has_groups’, ‘bbg_hidden_groups_only’ );`


    Boone Gorges
    Keymaster

    @boonebgorges

    In your code snippet, the magical part is user_id=, so you could do this
    `if ( strpos( bp_ajax_querystring( ‘groups’ ), ‘user_id=’ ) )`


    vonWolfehaus
    Member

    @vonwolfehaus

    Thanks for the help, but the snippet I put above works great. I added some other conditionals (and replaced user_id with `bp_loggedin_user_id()` of course) and now it’s working across the site perfectly, giving me complete control over how groups are listed in every situation… except the querystring seems to change randomly (today it just dropped the `type=active&action=active` part altogether). Hopefully it’ll stay put now. Anyway, thanks again.


    sdls
    Member

    @simon_said

    that totally helped me @boonebgorges thanks!.

    I’m trying to do something quite similar to Von. My goal is to create a new page, just like the
    buddypress forumns / groups / achievements setup where you have a table of contents with “view all” and “my ____”.

    Trying to integrate post content with this same setup…. sort of a “Browse all Posts” … “Browse My Posts”…. in the same format. This is both to take advantage of those nice little ajax togglers that modify the loop based on the ajax query…. but also to maintain visual consistency across the site.

    Using page templates a new table of contents has been created for these posts “post/index.php” and “post/post-loop.php” using the exact same HTML and CSS as the BP template…. so it looks good… same format..

    So…. you can toggle between “All Posts” and “My Posts”… but of course, the HTML and

    id’s are hooked into the original ajax loop mods for forumn/index.php, so when you click on it it loads the original loop for “All Forumns” and “My Forumns”.

    So first off…. trying to understand the Ajax call FROM the page… and I need to create a NEW one that triggers “All Posts” and “My Posts” correctly when the links are clicked on… Looking through bp_dtheme_ajax_querystring() in bp-themes/bp-default/_inc/ajax.php… wow this looks complicated.

    creating another action?
    add_action( ‘wp_ajax_posts_filter’, ‘bp_dtheme_object_template_loader’ );

    ANy help would be greatly appreciated!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] Trying to modify the group loop’ is closed to new replies.
Skip to toolbar