bp_get_template_part

Get a BuddyPress template part for display in a theme.

Description

(string) bp_get_template_part( (string) $slug, (null) $name = null ); 

Returns (string)

Path to located template. See {@link bp_locate_template()}.

Parameters (2)

0. $slug (string)
Template part slug. Used to generate filenames, eg friends for friends.php..
1. $name — Optional. (null) => null
Template part name. Used to generate secondary filenames, eg personal for activity-personal.php..

Usage

  1. if ( !function_exists( 'bp_get_template_part' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-template-loader.php'; 
  3.  
  4. // Template part slug. Used to generate filenames, 
  5. // eg 'friends' for 'friends.php'. 
  6. $slug = ''; 
  7.  
  8. // Optional. Template part name. Used to generate 
  9. // secondary filenames, eg 'personal' for 'activity-personal.php'. 
  10. $name = null; 
  11.  
  12. // NOTICE! Understand what this does before running. 
  13. $result = bp_get_template_part($slug, $name); 
  14.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-template-loader.php  
  1. function bp_get_template_part( $slug, $name = null ) { 
  2.  
  3. /** 
  4. * Fires at the start of bp_get_template_part(). 
  5. * This is a variable hook that is dependent on the slug passed in. 
  6. * @since 1.7.0 
  7. * @param string $slug Template part slug requested. 
  8. * @param string $name Template part name requested. 
  9. */ 
  10.  
  11. // Setup possible parts. 
  12. $templates = array(); 
  13. if ( isset( $name ) ) { 
  14. $templates[] = $slug . '-' . $name . '.php'; 
  15. $templates[] = $slug . '.php'; 
  16.  
  17. /** 
  18. * Filters the template parts to be loaded. 
  19. * @since 1.7.0 
  20. * @param array $templates Array of templates located. 
  21. * @param string $slug Template part slug requested. 
  22. * @param string $name Template part name requested. 
  23. */ 
  24. $templates = apply_filters( 'bp_get_template_part', $templates, $slug, $name ); 
  25.  
  26. // Return the part that is found. 
  27. return bp_locate_template( $templates, true, false );