活动循环

活动循环

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

The activity loop can be used to output a list of sitewide, member or member』s friends activity.
Standard Loop

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

scope optional
Pre-defined filtering of the activity stream. Show only activity for the scope you pass (based on the logged in user or a user_id you pass).

Accepted arguments: just-me, friends, groups, favorites, mentions
Default value: $bp->current_action

display_comments optional
Whether or not to display comments along with activity items. Threaded will show comments threaded under the activity. Stream will show comments within the actual stream in chronological order along with activity items.

Accepted arguments: false, threaded, stream
Default value: threaded

include optional
Pass an activity_id or string of comma separated ids to show only these entries.

Default value: false

sort optional
Sort the stream chronologically ascending or descending.

Accepted arguments: ASC, DESC
Default value: DESC

per_page optional
Number of activity items to show per page.

Default value: 20

page optional
Which page to return based on the number per page value.

Default value: 1

max optional
The limit on number of activity items that can be returned

Default value: false

show_hidden optional
Show items that have been hidden site wide? For example private or hidden group posts.

Default value: false

search_terms optional
Return only activity items that match these search terms

Default value: false

Filtering Options
Using filtering you can use the activity loop to return any specific information that has been recorded on the entire site. For example you could use it to return all of the latest comments site wide.
Listed below are the parameters you can use to filter the activity stream.

user_id optional
Limit activity items to a specific user ID. You can also pass in a comma separated string of user ids – see example below.

Default value: false (no filter)

object optional
The object type to filter on (can be any active component ID as well as custom component ID』s)

Example arguments: groups, friends, profile, status, blogs
Default value: false (no filter)

action optional
The action type to filter on (can be any active component action as well as custom component actions)

Example arguments: new_forum_post, new_blog_comment new_blog_post, friendship_created, joined_group, created_group, new_forum_topic, activity_update
Default value: false (no filter)

primary_id optional
The ID to filter on for a specific object. For example if you used groups as the object you could pass a group_id as the primary_id and restrict to that group.

Possible arguments: Any specific object ID
Default value: false (no filter)

secondary_id optional
The secondary ID to filter on for a specific object. For example if you used blogs as the object you could pass a blog_id as the primary_id and a post_id as the secondary_id the list all comments for that post using new_blog_comment as the action.

Possible arguments: Any specific object ID
Default value: false (no filter)

Filtering Examples
Filtering the activity loop to show only activity updates in the activity stream:

Use 『user_id』 to filter the activity loop to show only you and your friends in the activity stream:

Adding Commenting Support
Adding commenting support to your activity loop is pretty straightforward. You will first need to pass the 「display_comments=threaded」 parameter to your loop (see above).
Second you need to wrap all your activity code in a div with an 「activity」 class in order to make the ajax comments to work.
Finally, add the following code inside your loop, below 「activity-content」 div and above the closing list item tag:

<a href="" class="button acomment-reply bp-primary-action" id="acomment-comment-"><?php printf( __( 'Comment %s', 'buddypress' ), bp_activity_get_comment_count() ); ?>

<a href="" class="button fav bp-secondary-action" title="">

<a href="" class="button unfav bp-secondary-action" title="">

<form action="" method="post" id="ac-form-" class="ac-form">

<textarea id="ac-input-" class="ac-input" name="ac_input_">

<input type="submit" name="ac_form_submit" value="" />  
<input type="hidden" name="comment_form_id" value="" />

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注