Excerpt function in RC2
-
I hav updated my BP installation to RC2. Now the excerpt function on the drectory listing site is missing. How can I fix this?
-
Well, bp hasn’t tagged an RC2 yet. Did you mean the current trunk? What is the ‘excerpt function on the directory listing site’?
Okay, I meant the current trunk.
In the earlier trunk I had categorie list, like thsi one:
I tested long and short group descriptions. Whe I had a long description, the text (Group description) was automatically cropped and only the first few lines were displayed. Similiar to the excerpt funcrion from WordPress.
After the cropped text, I got brackets [..] displayed. Now, in the new trunk, the whole description gets displayed. Even if it has about 100 lines.
So waht can I do, to get the group description text cropped after x lines?
I see what you are saying. You want to be able to display an excerpt of the group description in the group directory. The best way I can recommend to you is to create a filter in bp-custom.php. Create one if it doesn’t exist in the bp /plugins/buddypress directory. This is a file where you can put all your custom mods for bp. In there, stick the following code:
function my_group_directory_description($text){
global $site_groups_template;
// only filter the description in the groups directory
if ($site_groups_template)
return bp_create_excerpt($text, 50);
else
return $text;
}
add_filter(‘bp_group_description’,’my_group_directory_description’)
That hooks a filter for the group description only when in the group directory and limits the work count to 50. You can modify the number of words limit by changing ’50’ to whatever word count you want.
The number of lines can’t be calculated easily. Too many variables. The bp_create_excerpt() function works by word count.
Next you are going to tell me that long descriptions run into the text for the ‘join/leave group’ area on the right of the directory. I know. I recommend that you ask somebody who enjoys banging their head against css for that. I’m just not very good at it.
Thanks again for your help. Oh, no, this time, I´m gonna tell you something :
´
<li class=”group-box”>
<div class=”left”>
“><?php bp_the_site_group_avatar_thumb() ?>
<?php $member_count = groups_get_groupmeta( $group->id, ‘total_member_count’ ) ?>
<?php echo ucwords($group->status) ?> <?php _e( ‘Group’, ‘buddypress’ ) ?>
<?php if ( $member_count == 1 ) : ?>
<?php printf( __( ‘%d member’, ‘buddypress’ ), $member_count ) ?>
<?php else : ?>
<?php printf( __( ‘%d members’, ‘buddypress’ ), $member_count ) ?>
<?php endif; ?>
</div>
<div class=”right”>
<div class=”group-top”>“><?php bp_the_site_group_name() ?><?php bp_group_join_button( $group ) ?>
<div class=”clear”></div>
</div>
<span class=”activity”><?php echo bp_core_get_last_activity( groups_get_groupmeta( $group->id, ‘last_activity’ ), __(‘active %s ago’) ) ?></span>
<div class=”excerpt”>
<?php // echo bp_create_excerpt( $group->description ) ?>
<?php bp_the_site_group_description() ?>
</div>
</div>
<div class=”clear”></div>
´
thsi is the code from my custom theme file. And here the Css, maybe there is a better solution, but it works:
´
.group-box{margin:15px auto 10px -30px;height:80px;width:800px;background: url(../images/group_list_item.jpg);
padding:10px 20px 25px 15px;list-style:none;text-align:justify }
.left{float:left;width:65px;height:82px;font-size:9px;color:#686868;line-height:11px;text-align:right}
.group-avatar img{border:1px solid #686868;height:60px;width:60px}
.right{float:left;height:82px;margin-left:5px;width:725px}
ul#letter-list li {float: left;height:25px; width:27px;margin-right:5px}
.group-top{height:20px;}
.group-link{text-decoration:none;font-size:16px;color: #ff7f00;float:left}
.group-link:hover{text-decoration:underline}
.excerpt{color:#1a1a1a;font-size:12px;}
.activity{font-size:11px;color:#686868; font-style:italic;display:block;margin:0;padding:0}
.leave_group, .join_group{float:right;display:block;padding:4px 0 0 24px;margin:0;font-size:10px;text-decoration:none;
color:#bd2100;height:21px;width:96px;background: url(../../bp-groups/images/leave_group.png);font-weight:bold}
.leave_group:hover, .join_group:hover{text-decoration:underline}
.join_group{color:green}
#group-dir-count{margin:0 0 5px 2px;font-size:12px;color:#686868}
´
Can you still tell me, how I get the recent activities that happened on the page?
I tried to call the function, but all I got, was the time.
Thanks
What function are you trying to call?
I try to get the latest activities, for example: User x has just build a group, or a comment was written in group….
Somethin like that, the user should get afirst overview, what happened in the commmunitiy within the last hours/days.
I see. I don’t think that the groups component has specific template functions for activity. Users and site wide is all if I remember correctly. You can always build one that filters group related stuff out of sitewide for just that group. I gotta go look.
Exactly. Sitewide is what I meant, Can you explain me, how to call it, maybe with some paramters, for example the number of last activities, that should be shown.
Was the code, i posted above, useful for you?
Thanks for the css. I haven’t tried it yet. Got sidetracked. Does any of that fix the overflow of text problem? If so then post the fix in trac as a patch or comment here: https://trac.buddypress.org/ticket/665
The problem with the sitewide activity is that you can get all the activities you want but it’s not really formatted for easy detection of specific group activities. The only indication that it’s from a specific group is the bp_activity_sitewide table fields ‘primary_link’ and ‘component_name’.
The component_name will be ‘groups’ and the primary_link will be something like this: http://ourcommoninterest.dev/groups/public
Take a look at bp-activity-classes.php get_sitewide_activity()
You can’t just make a call to a canned function with some parameters and get stuff for a specific group.
Yes, my css fixes that problem. The button also did not appear in opera, now it does. I have changed the html, too. So you have to apply bot changes, that it works. (css and html tags in the loop file).
How to use the sitewide activity tag?
In taht way, it does not work…><?php get_sitewide_activity() ?>
It also does not have to be formatted. The user should only see that there is something going on on the site and should get linke dto it, when he clicks.
I created a function that lives in the BP_Activity_Activity class that gets recent group activity. I uploaded it as a patch in trac https://trac.buddypress.org/ticket/668
get_sitewide_activity() returns all sorts of activity not related to that group. The new function that I uploaded gets just the activity for the specified group. If you apply that patch to the bp-activity-classes.php file and build some template php around it then you’ll get your activity display.
$activity = BP_Activity_Activity::get_activity_for_group( $site_groups_template->group, 2 );
That call above would work in the group directory template file. You’ll have to build something to display the returned $activity items like the site wide activity widget does.
See bp-activity-widgets.php for a guide. This little template tag below displays some raw unformated activity.
function my_the_site_group_activity($limit = 2){
global $site_groups_template;
$activity = BP_Activity_Activity::get_activity_for_group( $site_groups_template->group, $limit );
foreach ((array)$activity as $item){
echo apply_filters( ‘bp_activity_content’, bp_activity_content_filter( $item[‘content’], $item[‘date_recorded’], ”, true, false, true ) );
}
}
You can put that fn in your bp-custom.php file and try it out. I just stuck it in a div under the description tag in groups-loop.php for testing.
Many, many thanks.
How do I call the sitewide activity?
In this way, it does not work:
<?php get_sitewide_activity() ?>
How gets it calles on thsi site for example?
Now I tried this:
<?php get_sitewide_activity( $limit = 15 ) ?>
And got this error:
Fatal error: Call to undefined function: get_sitewide_activity() in […]p on line 126, so please tell, what did I wrong?
get_sitewide_activity() isn’t a function. It’s a method of the class BP_Activity_Activity and can only be called like $activity = BP_Activity_Activity::get_sitewide_activity()
It’s not going to give you what you are looking for. The new patch I put in trac will though. See my post above this.
get_sitewide_activity() returns all sorts of activity not related to that group
> that´s exactly what I need.I tried to call it with
<?php $activity = BP_Activity_Activity::get_sitewide_activity(); echo $activity ?>
The result, that is shown is Array.
The other unction, you have coded, will be needed later.
<?php bp_activity_widget_sitewide_activity($args) ?>
This already works a little. I still get an error message, but also that waht I want.
This is the error message:
extract() [function.extract]: First argument should be an array in
What do I have to change, that the message does not appear any longer?
I seem to be confused here. Where are you trying to show this sitewide activity? In any case the sitewide activity widget was not designed to be called as a template function.
Hi,
no reason to be confused.
I Want to use it like here:
https://buddypress.org/developers
In the left colum, under Latest Activity. The site whre I want to use it, as the starting page of my ite, located in the root.
- The topic ‘Excerpt function in RC2’ is closed to new replies.