Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this questionI'm often using the get_template_part()
function. I read the theme handbook about this function and the codex, but I'm not sure when this function can be useful. For example I've made some modular template parts that will have different functionality, like a swiper slider, image comparision or parallax effects. If I code a child theme manually, I will then modify it to be loaded whit the custom post category or name, but in a scenario where I want to sell my theme, How i can assign a post to this or that template part?
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this questionI'm often using the get_template_part()
function. I read the theme handbook about this function and the codex, but I'm not sure when this function can be useful. For example I've made some modular template parts that will have different functionality, like a swiper slider, image comparision or parallax effects. If I code a child theme manually, I will then modify it to be loaded whit the custom post category or name, but in a scenario where I want to sell my theme, How i can assign a post to this or that template part?
1 Answer
Reset to default 1get_template_part()
is useful for organizing chunks of your site into reusable parts. If you have parts of a larger template that might be used in multiple templates, it's useful to use get_template_part()
to pull these in rather than have the same markup in each separate template.
The real power of get_template_part()
is that it allows child themes to override these only these template parts.
For example, you mention a swiper slider. Using get_template_part()
, someone could create a child theme and override the swiper slider template part to be a grid of images instead of a slider. All they would have to do is create a template file that's named correctly in the child theme and WordPress would use this new template part instead of the parent theme's template part.