-
Notifications
You must be signed in to change notification settings - Fork 0
Using r_get_template_part
In WordPress, there is a function called get_template_part()
. This is a very
powerful function that allows a theme to have tiers of templates that fall back
to a default template.
One downfall of this function, though, is that if no default template is present, nothing will display. There are scenarios though, where this is not ideal.
Example: Say there is a custom post type, custom_type
.
<?php get_template_part( 'template-parts/custom_type', 'archive' ); ?>
These are the template part files that will be searched for in order:
child-theme/template-parts/custom_type-archive.php
parent-theme/template-parts/custom_type-archive.php
child-theme/template-parts/custom_type.php
parent-theme/template-parts/custom_type.php
If none of these files are present, the content will not be output.
This function adds an additional fallback template, content.php
. This file is
present in Responsive Framework, so it guarantees that the content will always
be displayed, even if specific template parts are not present in the child
theme.
<?php r_get_template_part( 'template-parts/custom_type', 'archive' ); ?>
This function will search for templates in the following order:
child-theme/template-parts/custom_type-archive.php
parent-theme/template-parts/custom_type-archive.php
child-theme/template-parts/custom_type.php
parent-theme/template-parts/custom_type.php
child-theme/template-parts/content.php
parent-theme/template-parts/content.php
This function should only be used to display single post template parts.
Sections should be loaded using get_template_part()
only.
Get started
Configuration
Build child themes
- Customizing CSS in a child theme
- Overriding templates in a child theme
- Code patterns
- Code reviews
- Pulling in Foundation Updates
- Merging and Creating a Pull Request
Sass
Javascript
PHP
- Coding Standards
- PHP Constants
- Temp PHP Code Patterns
- PHP Snippets
- How to Use Hooks
- Action Hooks
- Using Action Hooks To Output Markup
- Filter Hooks
Shortcodes
Templates
GitHub
Tasks
Contribute to the framework
- Framework Development and Release Workflows
- Documentation Template
- Testing your changes
- Creating a new release
- Migration Guide
- Needs Documentation
Code Examples
- Adding Content Container Classes
- Adding News Templates
- Adding Script Dependencies
- Changing Available Layouts and Default Layout
- Displaying a Fancy Gallery
- Loading a Custom Build of Modernizr
- Loading Modernizr in the Footer
- Using Action Hooks To Output Markup
- Understanding get_template_part
BU Developer Resources