最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customize theme with get_template_part()

programmeradmin2浏览0评论
Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 5 years ago.

Improve this question

I'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?

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 5 years ago.

Improve this question

I'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?

Share Improve this question asked Jun 8, 2019 at 14:06 YikkoYikko 155 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

get_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.

发布评论

评论列表(0)

  1. 暂无评论