-
Notifications
You must be signed in to change notification settings - Fork 0
PHP Guide
The ThinkWP Starter Theme is build with Timber and Twig on top of traditional WordPress tooling. Bringing Twig templates in to WP allows template markup to be separated from theme logic; as such the directory structure is built around that as an organizing principle.
Overall WordPress's template hierarchy has been maintained. At the top level of the theme folder you'll find php files containing template rendering logic, theme functions, and helper classes. The difference is comes in how those are deployed on load.
As Timber is written as a class that's meant to be extended by a theme, theme logic and functions have been moved to a class that's instantiated in functions.php. That class and supporting files live in the lib directory.
The main file where the Theme class extends Timber\Site class. The constructor for the class is where you can add WordPress actions, filters, and hooks that reference methods defined in the body of the class using the following syntax:
add_action( 'wp_hook_name', [ $this, 'name_of_method' ], $args... );Further down in the Theme class:
public function name_of_method( $args ) {
...
}If you need to reference a function inside a twig template you can add it to the timber context as well you can add values to the global timber context available to all twig templates, see menu example.
For complete documentation see our Twig in WordPress doc.
All template files live in the top level of the theme. The structure and naming follows WordPress's template hierarchy. Each file is used to setup individual contexts for and then render a Twig template file that contains template markup for the template. For more info see the index.phg example.
If you need to create a page template for the project you can do so in the templates directory following along with timber rendering conventions.
Custom Post Types
If you need custom post types in the theme there's a library in the theme's composer dependencies called Post Types that can be implemented in the register_post_types function to do so.
Custom Taxonomies
Similar to custom post types if you need custom taxonomies the Post Types library has functionality to implement them. Custom taxonomies can be added to the register_taxonomies function similar to Custom Post Types.