簡體   English   中英

使用bp-custom.php在BuddyPress(Wordpress)的附加選項卡中顯示配置文件字段

[英]Display profile fields in an extra tab in BuddyPress (Wordpress) using bp-custom.php

我在用戶的個人資料頁面上創建了一個額外的標簽,我想在其中顯示個人資料字段。

這就是我首先創建額外標簽的方式,我在其中創建了一個新的bp-custom.php

function profile_new_nav_item() {

    global $bp;

    bp_core_new_nav_item(
        array(
            'name'                => 'About',
            'slug'                => 'about',
          'default_subnav_slug' => 'extra_sub_tab', // We add this submenu item below
            'screen_function'     => 'view_manage_tab_main'
        )
    );
}

add_action( 'bp_setup_nav', 'profile_new_nav_item', 10 );

function view_manage_tab_main() {
    add_action( 'bp_template_content', 'bp_template_content_main_function' );
    bp_core_load_template( 'template_content' );
}

function bp_template_content_main_function() {
    if ( ! is_user_logged_in() ) {
        wp_login_form( array( 'echo' => true ) );
    }
}

function profile_new_subnav_item() {
    global $bp;

    bp_core_new_subnav_item( array(
        'name'            => 'Extra Sub Tab',
        'slug'            => 'extra_sub_tab',
        'parent_url'      => $bp->loggedin_user->domain . $bp->bp_nav[ 'about' ][ 'slug' ] . '/',
        'parent_slug'     => $bp->bp_nav[ 'about' ][ 'slug' ],
        'position'        => 10,
        'screen_function' => 'view_manage_sub_tab_main'
    ) );
}

add_action( 'bp_setup_nav', 'profile_new_subnav_item', 10 );

function view_manage_sub_tab_main() {
    add_action( 'bp_template_content', 'bp_template_content_sub_function' );
    bp_core_load_template( 'template_content' );
}

function bp_template_content_sub_function() {
    if ( is_user_logged_in() ) {
        echo 'you are here';
    } else {
        wp_login_form( array( 'echo' => true ) );
    }
}

看到echo 'you are here'; 在上一個功能中,我想在那里顯示配置文件字段。 我有下面的代碼,但我不知道如何將其嵌入其中。

如果我echo bp_the_profile_field()我得到以下錯誤

致命錯誤:在null上調用成員函數the_profile_field()

下面的代碼可以在另一頁上完美地工作,它可以獲取所有可用字段。

<div class="bp-widget <?php bp_the_profile_group_slug(); ?>">
<h4><?php bp_the_profile_group_name(); ?></h4>
<table class="profile-fields">
    <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
        <?php if ( bp_field_has_data() ) : ?>
            <tr<?php bp_field_css_class(); ?>>
                <td class="label"><?php bp_the_profile_field_name(); ?></td>
                <td class="data"><?php bp_the_profile_field_value(); ?></td>
            </tr>
        <?php endif; ?>
        <?php
        do_action( 'bp_profile_field_item' ); ?>
    <?php endwhile; ?>
</table></div>

替換為:

echo 'you are here';

有了這個:

bp_get_template_part( 'members/single/profile/profile-loop' );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM