將自定義選項卡新增到群組目錄

將自定義選項卡新增到群組目錄

Codex Home → Add Custom Tab to Groups Directory
Add Custom Tab to Groups Directory

This is an example of how to add a custom tab to the Groups Directory.
And call a custom template when that tab is clicked.
The same approach can be used to add a custom tab to the Members Directory.
The tab will be called Custom and it will load a template called groups-custom.php.
?12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879// add Custom tab on Groups Pagefunction asdf_groups_custom_tab() {     if ( bp_is_current_action( 'custom' ) )         return;     $button_args = array(        'id'         => 'groups-custom',        'component'  => 'groups',        'link_text'  => __( 'Custom', 'buddypress' ),        'link_title' => __( 'Custom', 'buddypress' ),        'link_class' => 'group-custom no-ajax',        'link_href'  => trailingslashit( bp_get_groups_directory_permalink() . 'custom' ),        'wrapper'    => false,        'block_self' => false,    );           ?>    

  •      0,            'post_title'     => 'Groups Custom',            'post_author'    => 0,            'post_date'      => 0,            'post_content'   => '',            'post_type'      => 'page',            'post_status'    => 'publish',            'is_page'        => true,            'comment_status' => 'closed'        ) );    }     public function create_content() {        return bp_buffer_template_part( 'groups/groups-custom', null, false );    } }
    This example assumes that the groups-custom.php template is in your theme at this location:
    .../wp-content/themes/your-theme/buddypress/groups/groups-custom.php
    If you want to load the template from a plugin, you need to register the location of the template:
    ?12345678910111213// add path to plugin templatesfunction asdf_register_template_location() {    return dirname( __FILE__ ) . '/templates/';}  function asdf_template_start() {     if( function_exists( 'bp_register_template_stack' ) )        bp_register_template_stack( 'asdf_register_template_location' ); }add_action( 'bp_init', 'asdf_template_start' );
    More info about using BP Theme Compat in plugins.

    發表回覆

    您的電子郵箱地址不會被公開。 必填項已用 * 標註