Templating in Cuisine means routing a certain post-type to a template-file. Therefor it’s done by the routing class. You can also use the routing class to route to a specific URL.
On this page we’ll be looking into routing to a template. If you’re looking to route your post type to a certain URL check out the page on URL-routing.
The Route-class is available through Cuisine’s Wrapper System, so you can start using it by adding
use Cuisine\Wrappers\Route
to the top of your php-document.
Cuisine changes the default template hierachy and makes it a bit simpeler. It looks for the following files, in order of priority:
For singular posts and pages:
And for overview pages:
Very Important: Cuisine looks for templates in your theme’s /pages folder. This can be changed using the cuisine_template_location filter.
See below for an example.
add_filter( 'cuisine_template_location', function( $location ){
return 'my-template-folder/'; //this needs a trailing slash
});
We recommend using Cuisine with it’s empty starter-theme Carte Blanche. It features a clear and Cuisine-ready folder structure. Out-of-the-box support for RequireJS and the Sass-asset pipeline and more good stuff you’ll be happy about. To learn more about using Cuisine and Carte Blanche together check our documentation page about it.
Routing post types to templates is done by using the WordPress template_include filter. This is considered best practise over using the template_redirect hook. All your registered templates will first be tested on existence and after that follow the regular WordPress theme hierarchy.
So, following our example of the project-post type, we’ll create a route for our post type project. We’ll want the overview page to be named /our-work and an single project can route to /project/project-name.
Route::url( 'project', 'our-work.php', 'project.php' );
That’s it. Here’s the breakdown for the example above:
The parameters passed down to the make-function are, in order of appearence:
post type slug The slug of the post-type we’re routing this template to.
overview template-name Name of the template file for an archive or overview
singular slug (optional) Name of the template file for a single post page.