Skip to:
Content
Pages
Categories
Search
Top
Bottom

BuddyPress Custom Nav and Page Template

  • Avatar of patrick30
    patrick30
    Participant

    @patrick30

    I am using buddypress for a social media site.

    I have create an xprofile field called “About”, and also added a new tab in the buddypress pages using the following code.

    function custom_setup_nav() {
      global $bp;
    
      bp_core_new_nav_item( array( 
            'name' => __( 'About', 'buddypress' ), 
            'slug' => 'about', 
            'position' => 30, 
            'screen_function' => 'about_page'
      ) );
    }
    
    add_action( 'bp_setup_nav', 'custom_setup_nav' );

    Now I have created an about page and named it about.php and uploaded it to /plugins/buddypress/bp-themes/bp-default/members/single

    And then added the following screen function

    function about_page() {
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/about' ) );
    }

    Now when I go to about page, I always get the members page displayed there, the page where the list of members are displayed and not the custom about.php page that I have uploaded, although the url remains the same, members/username/about/

    Is there something I am missing out on ?

    Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    Do not use your own template files. Use plugins.php and hook your content.

    function about_page() {
       add_action( 'bp_template_title', 'about_page_show_screen_title' );
       add_action( 'bp_template_content', 'about_page_show_screen_content' );
       bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    
    function about_page_show_screen_title() {
        echo 'About Page';
    }
    
    function about_page_show_screen_content() {
       echo 'the content of the page';
    }
    Avatar of patrick30
    patrick30
    Participant

    @patrick30

    @modemlooper And where would that file be located ? Should I make one in my theme ?

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    you can create a plugin for you extra code or us bp-custom.php

    http://codex.buddypress.org/plugindev/bp-custom-php/

    The contents of about.php go in the content function. There shouldn’t be a template file.

    Avatar of patrick30
    patrick30
    Participant

    @patrick30

    Hello Again,

    I have done exactly what you sent above. I have deleted all codes from functions.php and put them in bp-custom.php files, located in the plugins folder.

    Here are the contents of that file.

    http://pastebin.com/X7eGp87V

    Yet it always goes to the members page, the page where all members are listed :(

    Here is the link if you want to look, click on About and you will see what’s happening.

    http://tinyurl.com/m8y7zkm

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    show for displayed user

    remove that

    Avatar of patrick30
    patrick30
    Participant

    @patrick30

    I have already removed that and tried it.

    bp_core_new_nav_item( array( 
                'name' => __( 'About', 'buddypress' ), 
                'slug' => 'about', 
                'position' => 30, 
    		    'screen_function' => 'about_page',
    		    'css_id' => 'about'
          ) );
    Avatar of patrick30
    patrick30
    Participant

    @patrick30

    The thing is, no matter what I put, it keeps loading the “members” page in the about page

    Avatar of dzweb
    dzweb
    Participant

    @dzweb

    Try this, it worked for me!

    function custom_setup_nav() {
    global $bp;

    bp_core_new_nav_item( array(
    ‘name’ => __( ‘About’, ‘buddypress’ ),
    ‘slug’ => ‘about’,
    ‘position’ => 30,
    show_for_displayed_user’ => true,
    ‘default_subnav_slug’ => ‘about’,
    ‘item_css_id’ => ‘about’
    ) );
    }

    bp_core_new_subnav_item(
    array( ‘name’ => __( ‘About’, ‘buddypress’ ),
    ‘slug’ => ‘about’,
    ‘parent_url’ => $bp->loggedin_user->domain . ‘about’,
    ‘screen_function’ => ‘about’,
    ‘parent_slug’ => ‘about’,
    ‘position’ => 10,
    ‘item_css_id’ => ‘about’
    )
    );

    add_action( ‘bp_setup_nav’, ‘custom_setup_nav’ );

    function about_page() {
    add_action( ‘bp_template_content’, ‘about_content’ );
    bp_core_load_template( apply_filters( ‘bp_core_template_plugin’, ‘members/single/about’ ) );
    }

    function about_content(){
    //Put your content here!
    }

    Avatar of trumpxie
    trumpxie
    Participant

    @trumpxie

    hi @patrick30, any luck with this? I am having the same issue

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

You must be logged in to reply to this topic.