Using BuddyPress Cover Images inside the Member and Group Loops

Since BuddyPress 2.4 Groups and Member are able to upload Cover Images to be used on the single Group and Member pages. If you would like to use Cover Images when building custom loops you can use the following code to retrieve the cover images whilst inside your loop.

Inside Groups Loops Inside Groups Loops


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

<?php while (bp_groups()) : bp_the_group();?>

<?php // Get the Cover Image
$group_cover_image_url = bp_attachments_get_attachment(‘url’, array(
‘object_dir’ => ‘groups’,
‘item_id’ => bp_get_group_id(),
));
?>

<img src="<?php echo $group_cover_image_url; ?>">

<?php endwhile; ?>

<?php endif; ?>

Top ↑

Inside Members Loops Inside Members Loops


<?php if (bp_has_members($args)) : ?>

<?php while (bp_members()) : bp_the_member();?>

<?php // Get the Cover Image
$member_cover_image_url = bp_attachments_get_attachment(‘url’, array(
‘object_dir’ => ‘members’,
‘item_id’ => bp_get_member_id(),
));
?>

<img src="<?php echo $member_cover_image_url; ?>">

<?php endwhile; ?>

<?php endif; ?>