Template Hierarchy
Understanding BuddyX Pro’s template structure and WordPress template hierarchy for effective customization.
WordPress Template Hierarchy
Section titled “WordPress Template Hierarchy”BuddyX Pro follows the WordPress standard template hierarchy with custom enhancements for BuddyPress, WooCommerce, LearnDash, and FluentCart.
Template files the theme actually ships
Section titled “Template files the theme actually ships”These are the top-level template files present in buddyx-pro/ (5.1.4). The theme does not ship front-page.php, home.php, single-post.php, singular.php, or search.php - those views fall through to index.php (or archive.php) per the WordPress hierarchy.
404.php offline.php500.php page.phparchive.php searchform.phparchive-fluent-products.php sidebar.phparchive-sfwd-courses.php sidebar-buddypress.phpbbpress.php single.phpbuddypress.php single-fluent-products.phpcomment.php single-sfwd-courses.phpcomments.php single-sfwd-groups.phpfooter.php taxonomy-product-brands.phpheader.php taxonomy-product-categories.phpindex.phpBasic Hierarchy Flow
Section titled “Basic Hierarchy Flow”WordPress checks templates in this order:1. Child theme templates2. Parent theme templates3. WordPress default templatesCore Templates
Section titled “Core Templates”Homepage Templates
Section titled “Homepage Templates”Priority Order:
1. front-page.php # Static front page or blog2. home.php # Blog homepage3. page.php # If front page is a page4. index.php # Ultimate fallbackExample: Custom homepage
<?php get_header(); ?>
<div class="homepage-wrapper"> <?php while ( have_posts() ) { the_post(); get_template_part( 'template-parts/content', 'front-page' ); } ?></div>
<?php get_footer(); ?>Single Post Templates
Section titled “Single Post Templates”Priority Order:
1. single-{post-type}-{slug}.php # Single post by slug2. single-{post-type}.php # Single post by type3. single.php # Single post4. singular.php # Any single content5. index.php # FallbackExamples shipped by the theme:
single-sfwd-courses.php- LearnDash coursesingle-sfwd-groups.php- LearnDash groupsingle-fluent-products.php- FluentCart productsingle.php- Any single post (blog posts included; there is nosingle-post.php)
Page Templates
Section titled “Page Templates”Priority Order:
1. custom-template.php # Template Name: Custom2. page-{slug}.php # Page by slug3. page-{id}.php # Page by ID4. page.php # Default page5. singular.php # Any singular6. index.php # FallbackCustom Page Template:
<?php/** * Template Name: Full Width Page * Template Post Type: page * * @package buddyxpro */
get_header();?>
<div class="full-width-content"> <?php while ( have_posts() ) { the_post(); the_content(); } ?></div>
<?php get_footer(); ?>Archive Templates
Section titled “Archive Templates”Priority Order:
1. archive-{post-type}.php # Custom post type archive2. archive.php # Generic archive3. index.php # FallbackExamples:
archive-fluent-products.php- FluentCart shoparchive-sfwd-courses.php- LearnDash coursesarchive.php- Blog archives
Taxonomy Templates
Section titled “Taxonomy Templates”Priority Order:
1. taxonomy-{taxonomy}-{term}.php # Specific term2. taxonomy-{taxonomy}.php # Taxonomy archive3. taxonomy.php # Any taxonomy4. archive.php # Archive fallback5. index.php # Final fallbackExamples shipped by the theme:
taxonomy-product-categories.php- FluentCart product categoriestaxonomy-product-brands.php- FluentCart product brands
Plugin-Specific Templates
Section titled “Plugin-Specific Templates”BuddyPress Templates
Section titled “BuddyPress Templates”Template: buddypress.php
Used for all BuddyPress pages (members, groups, activity).
<?php/** * BuddyPress Page Template * * @package buddyxpro */
get_header();
$buddypress_sidebar = get_theme_mod( 'buddypress_sidebar_option', 'right' );?>
<?php do_action( 'buddyx_sub_header' ); ?>
<?php do_action( 'buddyx_before_content' ); ?>
<div id="primary" class="content-area"> <main id="main" class="site-main"> <?php // BuddyPress content if ( function_exists( 'bp_nouveau_wrapper_open' ) ) { bp_nouveau_wrapper_open(); } ?> </main></div>
<?phpif ( 'left' === $buddypress_sidebar || 'right' === $buddypress_sidebar ) { get_sidebar();}?>
<?php do_action( 'buddyx_after_content' ); ?>
<?php get_footer(); ?>bbPress Templates
Section titled “bbPress Templates”Template: bbpress.php
Used for forums, topics, and replies.
<?php/** * bbPress Page Template * * @package buddyxpro */
get_header();
$bbpress_sidebar = get_theme_mod( 'bbpress_sidebar_option', 'right' );?>
<?php do_action( 'buddyx_sub_header' ); ?>
<?php do_action( 'buddyx_before_content' ); ?>
<div id="primary" class="content-area"> <main id="main" class="site-main"> <?php while ( have_posts() ) { the_post(); the_content(); } ?> </main></div>
<?phpif ( 'left' === $bbpress_sidebar || 'right' === $bbpress_sidebar ) { get_sidebar();}?>
<?php do_action( 'buddyx_after_content' ); ?>
<?php get_footer(); ?>WooCommerce Templates
Section titled “WooCommerce Templates”Override Path: buddyx-pro/woocommerce/
The theme ships a small set of WooCommerce template overrides (only the files it needs to restyle - everything else falls back to WooCommerce core):
buddyx-pro/woocommerce/├── archive-product.php # Shop / product archive├── single-product.php # Product page├── cart/│ └── cart.php # Cart table├── single-product/│ └── rating.php # Product rating markup└── global/ └── quantity-input.php # Quantity inputLearnDash Templates
Section titled “LearnDash Templates”The theme ships two LearnDash single templates plus a course archive. Lesson, topic, and quiz views are handled by LearnDash’s own templates (the theme does not override them):
archive-sfwd-courses.php # Course archivesingle-sfwd-courses.php # Course singlesingle-sfwd-groups.php # Group singleExample: single-sfwd-groups.php
<?phpget_header();?>
<?php do_action( 'buddyx_sub_header' ); ?>
<?php do_action( 'buddyx_before_content' ); ?>
<div id="primary" class="content-area"> <main id="main" class="site-main"> <?php while ( have_posts() ) { the_post(); // LearnDash group content learndash_group_content(); } ?> </main></div>
<?php do_action( 'buddyx_after_content' ); ?>
<?php get_footer(); ?>FluentCart Templates
Section titled “FluentCart Templates”Templates:
archive-fluent-products.php- Shop pagetaxonomy-product-categories.php- Category archivetaxonomy-product-brands.php- Brand archive
Example: archive-fluent-products.php
<?phpget_header();?>
<?php do_action( 'buddyx_sub_header' ); ?>
<?php do_action( 'buddyx_before_content' ); ?>
<div id="primary" class="content-area"> <main id="main" class="site-main"> <?php // FluentCart renders its own content do_action( 'fluent_cart/template/main_content' ); ?> </main></div>
<?php do_action( 'buddyx_after_content' ); ?>
<?php get_footer(); ?>Template Parts
Section titled “Template Parts”Template parts are reusable components loaded with get_template_part().
Directory Structure
Section titled “Directory Structure”This mirrors the real template-parts/ tree in 5.1.4 (abridged):
template-parts/├── buddyx-page-header.php # Page header wrapper├── content-bbpress.php # bbPress content├── content-buddypress.php # BuddyPress content├── content-user-preview.php # Member preview card├── form.php # Generic form wrapper├── form-login.php # Login form├── form-register.php # Registration form├── form-vcard.php # vCard form├── content/ # Entry building blocks│ ├── entry.php # Entry dispatcher│ ├── entry-post.php # Post entry│ ├── entry-page.php # Page entry│ ├── entry-full-width.php # Full-width entry│ ├── entry-attachment.php # Attachment entry│ ├── entry-share.php # Share row│ ├── entry_header.php # Entry header│ ├── entry_title.php # Entry title│ ├── entry_content.php # Entry content│ ├── entry_summary.php # Entry summary / excerpt│ ├── entry_meta.php # Entry meta│ ├── entry_media.php # Entry media│ ├── entry_thumbnail.php # Entry thumbnail│ ├── entry_footer.php # Entry footer│ ├── entry_actions.php # Entry actions│ ├── entry_categories.php # Category list│ ├── entry_tags.php # Tag list│ ├── entry_taxonomies.php # Custom taxonomies│ ├── page_header.php # Page-header body│ ├── pagination.php # Pagination│ ├── related-posts.php # Related posts│ ├── error.php / error-404.php # Error states│ ├── error-500.php / error-offline.php│ └── entry_header-sfwd-courses.php # LearnDash course header├── header/│ ├── branding.php # Logo / site title│ ├── navigation.php # Primary + mobile nav│ ├── custom_header.php # Custom header image│ ├── buddypress-profile.php # BP profile menu│ └── buddyx-panel.php # Side panel├── layout/ # Blog layout variants│ ├── entry-default-layout.php│ ├── entry-grid-layout.php│ ├── entry-list-layout.php│ ├── entry-masonry-layout.php│ ├── entry-magazine-layout.php│ ├── entry-editorial-layout.php│ └── entry-minimal-layout.php├── post-format/ # Post-format media│ ├── entry-audio.php entry-gallery.php entry-image.php│ └── entry-link.php entry-quote.php entry-video.php└── footer/ └── info.php # Footer info / copyrightThere is no template-parts/content.php, content-none.php, content-page.php, header/mobile.php, or footer/footer-widgets.php. Page content is rendered by template-parts/content/entry-page.php (dispatched through entry.php); the mobile menu lives in header/navigation.php; footer widgets render from footer.php directly.
Using Template Parts
Section titled “Using Template Parts”// Load an entry part (dispatcher).get_template_part( 'template-parts/content/entry', get_post_type() );
// Load a specific header part.get_template_part( 'template-parts/header/branding' );
// Pass variablesset_query_var( 'custom_var', 'value' );get_template_part( 'template-parts/content/entry' );// Access in the part: get_query_var( 'custom_var' )Creating Custom Template Part
Section titled “Creating Custom Template Part”<?php/** * Template part for displaying custom post content * * @package buddyxpro */?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'custom-post' ); ?>> <header class="entry-header"> <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?> </header>
<div class="entry-content"> <?php the_content(); ?> </div>
<footer class="entry-footer"> <?php // Custom meta echo '<span class="custom-meta">'; echo esc_html( get_post_meta( get_the_ID(), 'custom_field', true ) ); echo '</span>'; ?> </footer></article>Partial Templates
Section titled “Partial Templates”Header
Section titled “Header”File: header.php
Structure:
<!DOCTYPE html><html <?php language_attributes(); ?>><head> <meta charset="<?php bloginfo( 'charset' ); ?>"> <meta name="viewport" content="width=device-width, initial-scale=1"> <?php wp_head(); ?></head>
<body <?php body_class(); ?>><?php wp_body_open(); ?><?php do_action( 'buddyx_body_top' ); ?>
<div id="page" class="site"> <?php do_action( 'buddyx_page_top' ); ?>
<?php do_action( 'buddyx_header_before' ); ?> <header id="masthead" class="site-header"> <?php do_action( 'buddyx_header_wrapper_before' ); ?> <!-- Branding + navigation template parts, header actions --> <?php do_action( 'buddyx_header_wrapper_after' ); ?> </header> <?php do_action( 'buddyx_header_after' ); ?>There is no
buddyx_headerhook. The real header hooks arebuddyx_header_before,buddyx_header_wrapper_before,buddyx_header_wrapper_after,buddyx_header_after, andbuddyx_header_actions(inside the menu-icons area). See Hooks & Filters.
Footer
Section titled “Footer”File: footer.php
Structure:
<?php do_action( 'buddyx_footer_before' ); ?>
<footer id="colophon" class="site-footer"> <!-- Footer content --> </footer>
<?php do_action( 'buddyx_footer_after' ); ?></div><!-- #page -->
<?php do_action( 'buddyx_page_bottom' ); ?><?php wp_footer(); ?><?php do_action( 'buddyx_body_bottom' ); ?>
</body></html>Sidebar
Section titled “Sidebar”File: sidebar.php
Structure:
<?phpif ( ! is_active_sidebar( 'sidebar-1' ) ) { return;}?>
<?php do_action( 'buddyx_sidebar_before' ); ?>
<aside id="secondary" class="widget-area"> <?php dynamic_sidebar( 'sidebar-1' ); ?></aside>
<?php do_action( 'buddyx_sidebar_after' ); ?>AMP Templates
Section titled “AMP Templates”Location: amp/
BuddyX Pro includes AMP-specific templates:
amp/├── single.php # AMP single post├── archive.php # AMP archive└── search.php # AMP search resultsAMP Template Detection:
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
Section titled “Custom Template Files”Search Results
Section titled “Search Results”The theme does not ship a search.php. Search results are rendered by index.php (the WordPress fallback), which loops through template-parts/content/entry for each result. searchform.php provides the search form markup, and amp/search.php handles AMP search. To customise search output, either add a search.php in your child theme or filter the entry parts.
404 Template
Section titled “404 Template”File: 404.php
<?phpget_header();?>
<div class="error-404 not-found"> <header class="page-header"> <h1 class="page-title"><?php esc_html_e( 'Oops! Page not found', 'buddyxpro' ); ?></h1> </header>
<div class="page-content"> <p><?php esc_html_e( 'The page you are looking for might have been removed.', 'buddyxpro' ); ?></p> <?php get_search_form(); ?> </div></div>
<?php get_footer(); ?>Override Templates in Child Theme
Section titled “Override Templates in Child Theme”Method 1: Direct Copy
Section titled “Method 1: Direct Copy”- Copy template from parent to child
- Keep same directory structure
- Modify as needed
# Example: Override headercp buddyx-pro/header.php buddyx-pro-child/header.phpMethod 2: Custom Template Location
Section titled “Method 2: Custom Template Location”// Child theme functions.phpadd_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
Section titled “Method 3: Plugin Integration Override”// Override FluentCart category templateadd_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
Section titled “Template Debugging”Show Current Template
Section titled “Show Current Template”// Add to child theme functions.phpadd_action( 'wp_footer', 'show_template_info' );function show_template_info() { if ( current_user_can( 'administrator' ) && WP_DEBUG ) { global $template; echo '<div style="position:fixed;bottom:0;left:0;background:#000;color:#fff;padding:10px;z-index:9999;">'; echo '<strong>Template:</strong> ' . basename( $template ); echo '</div>'; }}Template Hierarchy Debug
Section titled “Template Hierarchy Debug”// Show template loading orderadd_filter( 'template_include', 'debug_template_hierarchy', 9999 );function debug_template_hierarchy( $template ) { if ( WP_DEBUG ) { error_log( 'Template loaded: ' . $template ); } return $template;}Best Practices
Section titled “Best Practices”- 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
- Modify parent theme templates directly
- Hardcode URLs or paths
- Skip header/footer includes
- Duplicate template code
- Forget wp_head() and wp_footer()
- Mix business logic with presentation
- Use PHP short tags
Template Checklist
Section titled “Template Checklist”Before creating a custom template:
- Check if template part can be reused
- Follow WordPress naming conventions
- Include proper DocBlock
- Call
get_header()andget_footer() - Add theme action hooks
- Escape all output
- Test responsive design
- Validate HTML
- Test with WP_DEBUG enabled
- Document custom functionality

