Buddypress sitewide activity filters


On the sitewide activity page, rather than the dropdown letting me filter on posts, comments etc. I want to have "Posts" and "Comments" as tabs in the activity page menu, linking to /activity/posts or /activity/comments - so a new page that shows the filtered sitewide activity rather than using AJAX. Any idea how I do that?

I've managed to create the menu links by hooking into bp_activity_type_tabs but the pages /activity/posts and /activity/comments are blank (they show the site header but no page title or content). How do I get those pages to display the filtered activity?

I've managed to get this to work in the personal activity stream using bp_core_new_subnav_item to create subnav items under activity with their own screen functions, so thinking maybe using bp_core_new_nav_item but can't see how.

  • Sajid
    • DEV MAN’s Sidekick

    Hi @Turnpiece! Hope you are doing good today :slight_smile:

    Instead of using actin hook I suggest you to use the following snippet to add a menu item in navigation. According to BP documentation.

            'name' => __('Messages', 'buddypress'),
            'slug' => $bp->messages->slug,
            'position' => 50,
            'show_for_displayed_user' => false,
            'screen_function' => 'messages_screen_inbox',
            'default_subnav_slug' => 'inbox',
            'item_css_id' => $bp->messages->id

    The above code will add another item in navigation of BuddyPress themes and triggers "messages_screen_inbox" function to display the page content. If you go this way then you have to create your own function that will be responsible to render all contents of this page and all of its child pages.

    If you are comfortable of doing some code yourself then you can go this way.

    If you can grant me support access and provide screenshot with exact link of what filters you want to change into links. So I will be able to provide you more details and find a better way to display the page contents instead of using our own function from scratch.

    Look forward towards your response :slight_smile:

    Cheers, Sajid

  • Turnpiece
    • Design Lord, Child of Thor

    What I've done is this:

    function my_bp_activity_page() {
    	if ( bp_current_component() == 'activity' && ! bp_is_user() && ( bp_current_action() == 'posts' || bp_current_action() == 'comments' ) ) {
    		// The first variable here must match the name of your template file below
    		bp_get_template_part( 'activity/page', true );
    add_action( 'wp', 'my_bp_activity_page' );

    It's working but I suspect it's not the best way of doing this.

  • Sajid
    • DEV MAN’s Sidekick

    Hi @Turnpiece! Hope you are doing good today :slight_smile:

    The code you posted above seems correct to me. You are using proper hooks and BuddyPress function to load your template.

    Also the action hook you used to insert your custom tabs is also good way to add sub nave items, without modifying any core theme files.

    If you are modifying any core BP files then, its not right way.

    Feel free to post a reply, if need to :slight_smile:

    Cheers, Sajid

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.