Skip to:
Content
Pages
Categories
Search
Top
Bottom
Codex HomeDeveloper ResourcesLoops Reference → Groups Loop

Groups Loop

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

Standard Loop

<?php if ( bp_has_groups() ) : ?>

	<div class="pagination">

		<div class="pag-count" id="group-dir-count">
			<?php bp_groups_pagination_count() ?>
		</div>

		<div class="pagination-links" id="group-dir-pag">
			<?php bp_groups_pagination_links() ?>
		</div>

	</div>

	<ul id="groups-list" class="item-list">
	<?php while ( bp_groups() ) : bp_the_group(); ?>

		<li>
			<div class="item-avatar">
				<a href="<?php bp_group_permalink() ?>"><?php bp_group_avatar( 'type=thumb&width=50&height=50' ) ?></a>
			</div>

			<div class="item">
				<div class="item-title"><a href="<?php bp_group_permalink() ?>"><?php bp_group_name() ?></a></div>
				<div class="item-meta"><span class="activity"><?php printf( __( 'active %s ago', 'buddypress' ), bp_get_group_last_active() ) ?></span></div>

				<div class="item-desc"><?php bp_group_description_excerpt() ?></div>

				<?php do_action( 'bp_directory_groups_item' ) ?>
			</div>

			<div class="action">
				<?php bp_group_join_button() ?>

				<div class="meta">
					<?php bp_group_type() ?> / <?php bp_group_member_count() ?>
				</div>

				<?php do_action( 'bp_directory_groups_actions' ) ?>
			</div>

			<div class="clear"></div>
		</li>

	<?php endwhile; ?>
	</ul>

	<?php do_action( 'bp_after_groups_loop' ) ?>

<?php else: ?>

	<div id="message" class="info">
		<p><?php _e( 'There were no groups found.', 'buddypress' ) ?></p>
	</div>

<?php endif; ?>

Accepted Parameters

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

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' )
Skip to toolbar