Private Messages Loop
The private messages loop can be used to output a user’s private messages, both from their inbox and sentbox.
Standard Loop
<?php if ( bp_has_message_threads() ) : ?> <div class="pagination-count"> <?php bp_messages_pagination_count() ?> </div> <div class="pagination-links"> <?php bp_messages_pagination() ?> </div> <ul id="message-threads"> <?php while ( bp_message_threads() ) : bp_message_thread(); ?> <li> <!-- Example template tags you can use --> <?php bp_message_thread_id() ?> <?php bp_message_thread_has_unread() ?> <?php bp_message_thread_unread_count() ?> <?php bp_message_thread_avatar() ?> <?php bp_message_thread_from() ?> <?php bp_message_thread_last_post_date() ?> <?php bp_message_thread_view_link() ?> <?php bp_message_thread_subject() ?> <?php bp_message_thread_excerpt() ?> <?php bp_message_thread_delete_link() ?> </li> <?php endwhile; ?> </ul> <?php else: ?> <div id="message" class="info"> <p>There are no messages to display.</p> </div> <?php endif;?>
Accepted Parameters
The bp_has_message_threads()
function will accept a number of parameters that will manipulate the data being returned.
-
user_id optional
The ID of the user to fetch messages for. By default this will be the user_id of the user currently logged in.
- Default value:
$bp->loggedin_user->id
- Default value:
-
box optional
Which box should the loop display messages from?
- Accepted arguments:
inbox
,sentbox
,notices
- Default value:
inbox
- Accepted arguments:
-
per_page optional
The number of messages to display on a page before they are paginated to the next page.
- Default value:
10
- Default value:
-
max optional
The total number of messages to return.
- Default value:
false
(no limit)
- Default value:
Advanced Usage
Fetch inbox
messages for the user of ID 12
. Get a maximum of 5
messages.
<?php if ( bp_has_message_threads( 'user_id=12&box=inbox&max=5&amp;per_page=5' ) ) : ?>