Template Hierarchy
Understanding BuddyX Pro’s template structure and WordPress template hierarchy for effective customization.
WordPress Template Hierarchy
BuddyX Pro follows WordPress standard template hierarchy with custom enhancements for BuddyPress, WooCommerce, LearnDash, and FluentCart.
Basic Hierarchy Flow
WordPress checks templates in this order:
1. Child theme templates
2. Parent theme templates
3. WordPress default templates
Core Templates
Homepage Templates
Priority Order:
1. front-page.php # Static front page or blog
2. home.php # Blog homepage
3. page.php # If front page is a page
4. index.php # Ultimate fallback
Example: Custom homepage
// front-page.php
Single Post Templates
Priority Order:
1. single-{post-type}-{slug}.php # Single post by slug
2. single-{post-type}.php # Single post by type
3. single.php # Single post
4. singular.php # Any single content
5. index.php # Fallback
Examples:
single-sfwd-courses.php– LearnDash coursesingle-sfwd-groups.php– LearnDash groupsingle-post.php– Blog postsingle.php– Any single post
Page Templates
Priority Order:
1. custom-template.php # Template Name: Custom
2. page-{slug}.php # Page by slug
3. page-{id}.php # Page by ID
4. page.php # Default page
5. singular.php # Any singular
6. index.php # Fallback
Custom Page Template:
Archive Templates
Priority Order:
1. archive-{post-type}.php # Custom post type archive
2. archive.php # Generic archive
3. index.php # Fallback
Examples:
archive-fluent-products.php– FluentCart shoparchive-sfwd-courses.php– LearnDash coursesarchive.php– Blog archives
Taxonomy Templates
Priority Order:
1. taxonomy-{taxonomy}-{term}.php # Specific term
2. taxonomy-{taxonomy}.php # Taxonomy archive
3. taxonomy.php # Any taxonomy
4. archive.php # Archive fallback
5. index.php # Final fallback
Examples:
taxonomy-product-categories.php– FluentCart categoriestaxonomy-product-brands.php– FluentCart brandstaxonomy-course_category.php– LearnDash categories
Plugin-Specific Templates
BuddyPress Templates
Template: buddypress.php
Used for all BuddyPress pages (members, groups, activity).
bbPress Templates
Template: bbpress.php
Used for forums, topics, and replies.
WooCommerce Templates
Override Path: buddyx-pro/woocommerce/
WooCommerce template overrides follow WooCommerce structure:
buddyx-pro/woocommerce/
├── archive-product.php # Shop page
├── single-product.php # Product page
├── cart/
│ └── cart.php # Cart page
├── checkout/
│ └── form-checkout.php # Checkout page
└── myaccount/
└── my-account.php # Account page
LearnDash Templates
Hierarchy:
1. single-sfwd-courses.php # Course single
2. single-sfwd-lessons.php # Lesson single
3. single-sfwd-topic.php # Topic single
4. single-sfwd-quiz.php # Quiz single
5. single-sfwd-groups.php # Group single
Example: single-sfwd-groups.php
FluentCart Templates
Templates:
archive-fluent-products.php– Shop pagetaxonomy-product-categories.php– Category archivetaxonomy-product-brands.php– Brand archive
Example: archive-fluent-products.php
Template Parts
Template parts are reusable components loaded with gettemplatepart().
Directory Structure
template-parts/
├── content.php # Default post content
├── content-none.php # No content found
├── content-page.php # Page content
├── buddyx-page-header.php # Page header
├── form-login.php # Login form
├── form-register.php # Registration form
├── header/
│ ├── mobile.php # Mobile header
│ └── buddypress-profile.php # BP profile menu
└── footer/
└── footer-widgets.php # Footer widget area
Using Template Parts
// Load template part
get_template_part( 'template-parts/content', 'page' );
// Loads: template-parts/content-page.php
// With specific context
get_template_part( 'template-parts/header-settings/mobile' );
// Loads: template-parts/header-settings/mobile.php
// Pass variables
set_query_var( 'custom_var', 'value' );
get_template_part( 'template-parts/custom' );
// Access in template: get_query_var( 'custom_var' )
Creating Custom Template Part
// template-parts/content-custom.php
" >
', '' ); ?>
Partial Templates
Header
File: header.php
Structure:
>
">
>
Footer
File: footer.php
Structure:
Sidebar
File: sidebar.php
Structure:
AMP Templates
Location: amp/
BuddyX Pro includes AMP-specific templates:
amp/
├── single.php # AMP single post
├── archive.php # AMP archive
└── search.php # AMP search results
AMP Template Detection:
// functions.php
add_filter( 'template_include', 'buddyx_theme_amp_templatre_include', '9999992233720368547758099' );
function buddyx_theme_amp_templatre_include( $template_file ) {
if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
if ( is_single() ) {
$template_file = get_template_directory() . '/amp/single.php';
}
if ( is_archive() ) {
$template_file = get_template_directory() . '/amp/archive.php';
}
}
return $template_file;
}
Custom Template Files
Search Template
File: search.php
404 Template
File: 404.php
Override Templates in Child Theme
Method 1: Direct Copy
- Copy template from parent to child
- Keep same directory structure
- Modify as needed
# Example: Override header
cp buddyx-pro/header.php buddyx-pro-child/header.php
Method 2: Custom Template Location
// Child theme functions.php
add_filter( 'template_include', 'child_custom_template', 99 );
function child_custom_template( $template ) {
if ( is_page( 'custom' ) ) {
$custom_template = get_stylesheet_directory() . '/templates/custom-page.php';
if ( file_exists( $custom_template ) ) {
return $custom_template;
}
}
return $template;
}
Method 3: Plugin Integration Override
// Override FluentCart category template
add_filter( 'template_include', 'child_fluentcart_templates', 100 );
function child_fluentcart_templates( $template ) {
if ( is_tax( 'product-categories' ) ) {
$custom = get_stylesheet_directory() . '/fluentcart/taxonomy-categories.php';
if ( file_exists( $custom ) ) {
return $custom;
}
}
return $template;
}
Template Debugging
Show Current Template
// Add to child theme functions.php
add_action( 'wp_footer', 'show_template_info' );
function show_template_info() {
if ( current_user_can( 'administrator' ) && WP_DEBUG ) {
global $template;
echo '';
echo 'Template: ' . basename( $template );
echo '';
}
}
Template Hierarchy Debug
// Show template loading order
add_filter( 'template_include', 'debug_template_hierarchy', 9999 );
function debug_template_hierarchy( $template ) {
if ( WP_DEBUG ) {
error_log( 'Template loaded: ' . $template );
}
return $template;
}
Best Practices
Do
- Follow WordPress template hierarchy
- Use child theme for overrides
- Keep consistent file structure
- Document custom templates
- Use template parts for reusable components
- Test template changes thoroughly
- Escape all output
- Use proper WordPress functions
Don’t
- Modify parent theme templates directly
- Hardcode URLs or paths
- Skip header/footer includes
- Duplicate template code
- Forget wphead() and wpfooter()
- Mix business logic with presentation
- Use PHP short tags
Template Checklist
Before creating a custom template:
- Check if template part can be reused
- Follow WordPress naming conventions
- Include proper DocBlock
- Call
getheader()andgetfooter() - Add theme action hooks
- Escape all output
- Test responsive design
- Validate HTML
- Test with WP_DEBUG enabled
- Document custom functionality
