群組迴圈

群組迴圈

Codex Home → Developer Resources → Loops Reference → Groups Loop
Groups Loop

The site groups loop can be used to output a list of groups created on your site.
Standard Loop

  • <a href="">
    <a href="">

    /

Accepted Parameters
The bp_has_groups() function will accept a number of parameters that will manipulate the data being returned.

type optional
Defines the type of groups to return.

Accepted arguments: active, newest, popular, random, alphabetical, most-forum-topics, most-forum-posts
Default value: active

per_page optional
The number of groups to display on a page before they are paginated to the next page.

Default value: 10

page optional
The page to display.

Default value: 1

max optional
The total number of groups to return.

Default value: false (no limit)

user_id optional
Return only groups that this user is a member of.

Default value: false

slug optional
Return only the group that matches this slug

Default value: false

search_terms optional
Return only groups that match these search terms

Default value: false

meta_query optional
Return only groups that match a meta key and value

Default value: false

populate_extras optional
Fetch extra meta for each group such as if the logged in user is a member, or is banned.

Default value: true

Example Code to Use Parameters
This is the way you can add the various parameters directly:
bp_has_groups( 'type=random&max=3&user_id=' . $user_id )

If you want to use multiple parameters it』s sometimes easier to use an array like this:
$args = array(
'type' => 'random',
'max' => 3,
'user_id' => $user_id
);
if ( bp_has_groups ( $args ) ) { ...

If you want to show all groups, regardless of whether the the logged-in or displayed member belongs to them, use this:
bp_has_groups( 'user_id=NULL' )

發表回覆

您的電子郵箱地址不會被公開。 必填項已用 * 標註