admin管理员组文章数量:1434924
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
1 Answer
Reset to default 0I 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.
本文标签: BuddyPresshow can I call the template Wordpress would have chosen (template hierarchy)
版权声明:本文标题:BuddyPress : how can I call the template Wordpress would have chosen (template hierarchy)? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745634485a2667470.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论