Skip to:
Content
Pages
Categories
Search
Top
Bottom

Displaying members favorite activities


  • colabsadmin
    Participant

    @colabsadmin

    Hello. I’ve created a new member nav item called favorites that will contain listings of all favorites on the site (Posts, CPTs, Topics, Activities). Everything is working except for the activities. Here’s how I’m creating the subnav

    // Favorite activity items
    bp_core_new_subnav_item(array(
    	'name'            => __( 'Activity', 'Profile activity screen sub nav', 'kleo' ),
    	'slug'            => 'activity',
    	'parent_url'      => $bp->displayed_user->domain . $bp->bp_nav['favorites']['slug'] . '/',
    	'parent_slug'     => $bp->bp_nav['favorites']['slug'],
    	'screen_function' => 'bp_activity_screen_favorites',
    	'position'        => 10,
    	'item_css_id'     => 'activity-favs'
    ));

    The subnav item is displayed, but nothing prints out. Is there a conditional somewhere that tells bp to only print out the favorite activities if you’re withing the Activity nav screen?

Viewing 7 replies - 1 through 7 (of 7 total)

  • colabsadmin
    Participant

    @colabsadmin

    Sorry for posting in “installing”. Tried to edit, but it takes me to buddypress.org main page. Wont allow me to edit.


    danbp
    Participant

    @danbp

    Topic moved to Creating & Extending forum


    danbp
    Participant

    @danbp

    There is already a my favorites tab in BuddyPress menu. Don’t know what you’re trying to do, but here is a code example you can try(or study).

    Add it to your child-theme functions.php or bp-cutom.php

    function my_test_setup_nav() {
    global $bp;
    $parent_slug = 'test';
    $child_slug = 'test_sub';
    
    	//name, slug, screen, position, default subnav
    	bp_core_new_nav_item( array(
    		'name' 					=> __( 'Company Labs' ),
    		'slug' 					=> $parent_slug,
    		'screen_function' 		=> 'my_test_page_function_to_show_screen',
    		'position' 				=> 40,
    		'default_subnav_slug' 	=> $child_slug 
    	) );
    
    	//Add the subnav items to the profile/
    	// name, slug, parent_url, parent slug, screen function
    
    	// Tab 
    	bp_core_new_subnav_item( array( 
    		'name' 					=> __( 'Company Favs' ), 
    		'slug' 					=> $child_slug, 
    		'parent_url' 			=> $bp->loggedin_user->domain . $parent_slug.'/', 
    		'parent_slug'			=> $parent_slug, 
    		'screen_function' 		=> 'my_test_page_function_to_show_screen'
    		) );
    	}
    
    	// tab
    	function my_test_page_function_to_show_screen() {
    
    	//add title and content here – last is to call the members plugin.php template
    
    	add_action( 'bp_template_title', 'my_test_page_function_to_show_screen_title' );
    	add_action( 'bp_template_content', 'my_test_page_function_to_show_screen_content' );
    	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    	}
    
    	function my_test_page_function_to_show_screen_title() {
    	echo 'Taskforce Titled';
    	}
    
    	function my_test_page_function_to_show_screen_content() {
    	echo 'Taskforce content';
    	do_action( my_test_post);
    	}
    
    add_action( 'bp_setup_nav', 'my_test_setup_nav' );
    
    function my_test_fav_custom_content() {
    ?>
    	<h3>Hello Company !</h3>
    	<p>Lorem ipsum de facto est</p>
    <?php	
    }
    add_action(  'my_test_post', 'my_test_fav_custom_content' );

    colabsadmin
    Participant

    @colabsadmin

    Sorry I thought I was clear. I dont need an example of how to create the tab and the submenus.

    What I did was write a class that creates a top level member area tab called Favorites that consolidates all types of favorites within a single tab. https://github.com/colabsadmin/bp-favorites/blob/master/bp-favorites.php

    The submenus that have been created so far are Activity, Topics, Posts and a few more for some CPTs that I’ve written. This will make it easier for my users to find their favorites when they cant remember if it came from a topic, posts, activity, etc. Instead of jumping around from tab to tab, its all in one tab. The only submenu that doesnt work is Activity. The code, which I provided in my first question, was copied directly from Buddypress core code with one change to use ‘bp_core_new_subnav_item’. I used similar code to display content in all the other submenus. For example, the following shows the favorite topics

    // Favorite topics
    bp_core_new_subnav_item( array(
    		'name'            => __( 'Topics', 'kleo' ),
    		'slug'            => "topics",
    		'parent_url'      => $bp->displayed_user->domain . $bp->bp_nav['favorites']['slug'] . '/',
    		'parent_slug'     => $bp->bp_nav['favorites']['slug'],
    		'screen_function' => 'bbp_member_forums_screen_favorites',
    		'position'        => 10,
    		'item_css_id'     => 'favorites'
    ));
    

    So, my question, does bp_activity_screen_favorites() only work within the context of /members/membername/activity action? Or can it be used elsewhere as in /members/membersname/favorites?


    shanebp
    Moderator

    @shanebp

    bp_activity_screen_favorites() loads that screen.

    Try using: bp_activity_get_user_favorites()

    Looking thru the source code will answer these kinds of questions.


    colabsadmin
    Participant

    @colabsadmin

    That’s what I’m trying to do. Load that screen, but under a different tab.


    colabsadmin
    Participant

    @colabsadmin

    The only way I got this to work is by duplicating the activity loop (passing the scope=favorites argument) and all of the code that formats the activities, which I was trying to avoid.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Displaying members favorite activities’ is closed to new replies.
Skip to toolbar