How can I set "Show NewBlogPosts" as default on acitivity-stream?
-
I have the activity as home.
How can I set the “Show new BlogPosts” instead of “No filter” as default?
Thanks for help.
-
Nobody here who can help? It’s the only problem I still have before I can upgrade my site to bp 1.2.1.
I read https://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-activity-stream-loop/
an I tried
<?php if ( bp_has_activities('action=new_blog_post') ) : ?>
instead of
<?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) ) ) : ?>
in activity-loop.php, but then only the new blog posts are shown, no matter which options I take.
I want the new blog posts only as default and not as only option.
Please, if anybody could be so kind to tell me the code and where to put it, I would be vergly glad.
I’m still trying to find a solution.
I think there are two things that have to be done:
1. Chose “Show Blog Posts” in the selection table to be set first.
2. Tell the code that there should be shown the filtered activity stream instead of the whole one.
I found the solution for 1.:
I created a folder “activity” in my child theme and copied the index.php from the bp-default-theme activity-folder inside. Then I changed in index.php the following line:
<option value="new_blog_post"><?php _e( 'Show Blog Posts', 'buddypress' ) ?></option>
and have this instead of it now:
<option value="new_blog_post" selected><?php _e( 'Show Blog Posts', 'buddypress' ) ?></option>
Now, the Blog-Post option is shown first in the selection, BUT there are still all activities without filter on the page. So step 2 has also to be done and I don’t know where.
I would appreciate any help.
This stuff is making me crazy.
I thought about another solution and wanted to have blog posts, comments and forum stuff on the acitivity stream.
I tried this:
<?php if ( bp_has_activities('action=new_blog_post&new_blog_comment&new_forum_post&new_forum_topic') ) : ?>
but it seems to be impossible to have mor than one action choosen, because only the blog posts are shown.
So, this thing leads me back to the question, how I could have blog posts instead of no filter as default.
Hi nickrita,
Got your PM.
Can you post an enhancement ticket on Trac – https://trac.buddypress.org/newticket (use the same login info you use here) – asking for an admin option to select the default filter?
ray, I posted it and it’s ticket 2147.
But I really would like to have it before bp 1.2.2 comes. It doesn’t matter if I cannot override it in a child theme. I would change the bp-code, if I only knew, how.
I don’t know how to fix this in a theme or through a plugin function. The reason is that the activity page is the default, which is shown when no $object is passed to bp_dtheme_ajax_querystring. bp_dtheme_ajax_querystring returns false when there’s no object, so there’s no content to filter.
Here’s a way to more or less fix the problem:
1) Put this in functions.php of your theme:
function members_alpha_by_default( $query_string ) {
global $bp;
if ( $bp->current_component == BP_ACTIVITY_SLUG || !$bp->current_component)
$query_string = 'type=new_blog_post&action=new_blog_post';
return $query_string;
}
add_filter( 'bp_dtheme_ajax_querystring', 'members_alpha_by_default' );2) In bp-themes/default/_inc/ajax.php, comment out lines 23 and 24, which read
if ( empty( $object ) )
return false;You’ll lose this hack, of course, when you upgrade BP.
Boone Gorges, thank you very much for your help.
BUT: It doesn’t work.
Now the acitivity-stream ONLY shows the new blog posts, no matter which filter-option I use.
I want the other options to be there, and the new blog posts as first of them, not as only one.
Yeah, you’re right. Try this. It seems to work for me. Make sure you clear your cookies before testing.
function blog_posts_by_default( $query_string ) {
global $bp;
if ( ($bp->current_component == BP_ACTIVITY_SLUG || !$bp->current_component) && !$query_string)
$query_string = 'type=new_blog_post&action=new_blog_post';
return $query_string;
}
add_filter( 'bp_dtheme_ajax_querystring', 'blog_posts_by_default' );Boone, you’re my hero! It works!
I didn’t do the hack in the ajax.php now.
The result of your function is, that new blog posts are shown first and I have all options except “no filter”. Selecting “no filter” there are the new blog posts, too. This doesn’t matter for me, as I am going to delete the no-filter-option in the seletion-box.
I’m going to test the function completely this evening, but for the moment it looks pretty good!
Thank you very, very much!
You’re welcome! If you make more changes, please post them to this thread so that others can benefit.
Boone, I tested and your code works pretty good!
I did two things:
1. Like I wrote above, I created a folder “activity” in my child theme and copied the index.php from the bp-default-theme activity-folder inside. Then I changed in index.php the following line:
<option value="new_blog_post"><?php _e( 'Show Blog Posts', 'buddypress' ) ?></option>
and have this instead of it now:
<option value="new_blog_post" selected><?php _e( 'Show Blog Posts', 'buddypress' ) ?></option>
Now, the Blog-Post option is shown first in the selection.
2. In the same index.php I deleted the no-filter option:
<option value="-1"><?php _e( 'No Filter', 'buddypress' ) ?></option>
That’s it.
You can see it working here: http://tastentango.de
It works great on the first page, but when I coose “Load more”, then everything shown is with “no filter”
you can see it here: http://netzkritzler.de
I have the same problem when creating activity loops with specific arguments. I think it works if you don’t use the “Load more”, but regular pagination. However it is not nearly as fun.
I think the load more show use the arguments passed in. Could this be a bug or is this expected behavior?
OK, here’s a bit of a refinement.
function blog_posts_by_default( $query_string ) {
global $bp;
if ( !$query_string )
$query_string = '';
if ( ($bp->current_component == BP_ACTIVITY_SLUG || !$bp->current_component) && !strpos($query_string, 'type='))
$query_string .= 'type=new_blog_post&action=new_blog_post';
return $query_string;
}
add_filter( 'bp_dtheme_ajax_querystring', 'blog_posts_by_default' );Boone, this works, but now choosing all options only the blog posts are shown.
function blog_posts_by_default( $query_string ) {
global $bp;
if ( !$query_string )
$query_string = '';
if ( ($bp->current_component == BP_ACTIVITY_SLUG || !$bp->current_component) ) {
if ( strpos( $query_string, 'action' ) == 0 )
$query_string .= '&type=activity_update&action=activity_update';
}
return $query_string;
}
add_filter( 'bp_dtheme_ajax_querystring', 'blog_posts_by_default' );Boone, thank you very much! This works!
Posted too early, it doesn’t work. As soon as someone writes an @mention, the activity only shows the @mentions and not the blog posts first.
This stuff seem to be a never ending story.
I use Boones first code now, with the fault in the “load more”.
Oh, that’s probably because it’s set to get activity types. Go figure. In the code I most recently posted, replace
&type=activity_update&action=activity_update
with
&type=new_blog_post&action=new_blog_post
(When I was writing the function on my own installation I used activity items as my test case and forgot to change it to blog posts before pasting it here.)
Thank you very much Boone for still helping. I tested it and until now, it works.
It works, until I try to set pagination instead of load more.
Mmh. Either the pagination code is wrong or there’ s an incompatibility between pagination and boones code.
The pagination links are shown, but they don’t work.
The pagination-code was wrong.
Solution is here: https://buddypress.org/forums/topic/how-can-i-get-a-paged-activity-stream-instead-of-the-load-more
This is ALMOST enough to make you my hero.
BUT, is there any way to make this work on front page, but not in the activity feed on user profile?
Basically, when my users log in, they are sendt directly to their profile. On the streams there, I would still like to let them see status updates etc as default, as it is then limited to themselves and their friends, not everyone on the site.
maybe wrap the function in another if statement? Or would one perhaps have to create an entirely new slug?
Ok, sorry to ask this but can someone please dumb this down for me a little bit in 1 post in what files i need to make the changes and what all changes i do need to make in order to get my site to just pull the “show updates”? I tried messing around and kept getting errors.
Hi,
Thanks for this tips.
I need to display as delault “activity_update” AND “new_blog_post” AND “new_blog_comment”. How can I add this to your code ?
Any idea ?
Guillaume.
- The topic ‘How can I set "Show NewBlogPosts" as default on acitivity-stream?’ is closed to new replies.