BuddyPress : how can I call the template Wordpress would have chosen (template hierarchy)?

playing with BuddyPress here !I made some new user profile pages, and when I display the content, I want to make a new p

playing with BuddyPress here !

I made some new user profile pages, and when I display the content, I want to make a new posts query, and display the loop.

Thing is, I want to display that loop using the template Wordpress would have chosen himself - depending on the query, on the theme installed, etc; well, depending of the template hierarchy.

Will it be archive-{post_type}.php, archive.php, index.php ? Something else ?

I need WP to return me the template to load.

Is that possible and how ?

Thanks a lot !

add_action( 'bp_setup_nav','register_music_menu', 99 );

function register_music_menu() {
    global $bp;

    ...

    bp_core_new_subnav_item( array(
        'name'            => __( 'Playlists', 'wpsstm' ),
        'slug'            => WPSSTM_PLAYLISTS_SLUG,
        'parent_url'      => $bp->displayed_user->domain . WPSSTM_BASE_SLUG . '/',
        'parent_slug'     => WPSSTM_BASE_SLUG,
        'screen_function' => 'view_user_static_playlists',
    ) );
}

function view_user_static_playlists() {
    add_action( 'bp_template_title', 'user_static_playlists_subnav_title' );
    add_action( 'bp_template_content','user_static_playlists_subnav_content');
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}

function user_static_playlists_subnav_content(){
    ...
    //overriding WP Qyery
    query_posts( $args );

    /*HERE,
    I would like to embed a template to display my loop; 
    and I want this to be the template WP would have chosen based on the                 query.  
    In this precise case, it would be the archive template of my custom post type.  
    But, depending of the user's theme; I don't know if it will be archive-{post_type}.php, archive.php, index.php...
    Well, I just want to get the path WP would have chosen.

    */
    locate_template( $template,true,false );

}

playing with BuddyPress here !

I made some new user profile pages, and when I display the content, I want to make a new posts query, and display the loop.

Thing is, I want to display that loop using the template Wordpress would have chosen himself - depending on the query, on the theme installed, etc; well, depending of the template hierarchy.

Will it be archive-{post_type}.php, archive.php, index.php ? Something else ?

I need WP to return me the template to load.

Is that possible and how ?

Thanks a lot !

add_action( 'bp_setup_nav','register_music_menu', 99 );

function register_music_menu() {
    global $bp;

    ...

    bp_core_new_subnav_item( array(
        'name'            => __( 'Playlists', 'wpsstm' ),
        'slug'            => WPSSTM_PLAYLISTS_SLUG,
        'parent_url'      => $bp->displayed_user->domain . WPSSTM_BASE_SLUG . '/',
        'parent_slug'     => WPSSTM_BASE_SLUG,
        'screen_function' => 'view_user_static_playlists',
    ) );
}

function view_user_static_playlists() {
    add_action( 'bp_template_title', 'user_static_playlists_subnav_title' );
    add_action( 'bp_template_content','user_static_playlists_subnav_content');
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}

function user_static_playlists_subnav_content(){
    ...
    //overriding WP Qyery
    query_posts( $args );

    /*HERE,
    I would like to embed a template to display my loop; 
    and I want this to be the template WP would have chosen based on the                 query.  
    In this precise case, it would be the archive template of my custom post type.  
    But, depending of the user's theme; I don't know if it will be archive-{post_type}.php, archive.php, index.php...
    Well, I just want to get the path WP would have chosen.

    */
    locate_template( $template,true,false );

}
Share Improve this question asked Apr 2, 2019 at 17:46 gordiegordie 4925 silver badges19 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I think that you're over engineering the problem here. If all you need to do is get the appropriate archive template, whatever that may be, then use get_archive_template() although you may need to use the {$type}_template_hierarchy filter on get_query_template() to add index.php to the possible results.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745634485a4637305.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信