0

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 );

}

1 Answer 1

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.

2
  • What I don't get is that, how can I get the appropriate archive template when I don't know the files of the theme the website uses ? (i'm coding a plugin)
    – gordie
    Apr 2, 2019 at 20:52
  • get_archive_template, if I'm reading the code right, should find the appropriate template file for you.
    – mrben522
    Apr 3, 2019 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.