wordpress主题_什么是WordPress儿童主题? 优点,缺点等

wordpress主题

A lot of our users ask us which template are we using? Our response is that we are using a custom child theme built on the Genesis theme framework. The follow up question most of the time is a two-part question. What is a WordPress theme framework? The second part of the question is what is a WordPress child theme? We have already explained what is a WordPress theme framework in our previous article. In this article, we will do our best to answer questions like what is a WordPress child theme, when should you create a child theme, why do people create child themes, and lastly advantages and disadvantages of using a child theme. Our hope is that after reading this article, you will have a clear understanding of what is a WordPress child theme, and you will know whether you should use a child theme or not.

许多用户问我们使用的是哪个模板? 我们的回答是,我们正在使用基于Genesis主题框架构建的自定义子主题。 大多数情况下,后续问题是一个分为两部分的问题。 什么是WordPress主题框架? 问题的第二部分是什么是WordPress子主题? 在上一篇文章中,我们已经解释了什么是WordPress主题框架 。 在本文中,我们将尽力回答以下问题:什么是WordPress子主题,何时创建子主题,人们为什么创建子主题以及使用子主题的优缺点。 我们的希望是,阅读本文后,您将对什么是WordPress子主题有清楚的了解,并且知道是否应使用子主题。

WordPress Child Themes
什么是WordPress儿童主题 (What is a WordPress Child Theme)

A WordPress child theme is a WordPress theme that inherits its functionality from another WordPress theme, the parent theme. Child themes are often used when you want to customize or tweak an existing WordPress theme without losing the ability to upgrade that theme. In the past, there was no easy way of updating WordPress themes without losing all the custom styling and changes that you had made. This becomes chaos when all the sudden you find out a widely used script in popular themes has a major exploit, and you need to update your themes ASAP. It becomes a tough choice because on one hand, you would lose all the custom styles if you update. On the other hand, you risk your site getting hacked if you don’t update fast enough.

WordPress子主题是WordPress主题,它继承了另一个WordPress主题父主题的功能。 当您要自定义或调整现有WordPress主题而又不失去升级该主题的能力时,通常使用子主题。 过去,在不丢失所有自定义样式和更改的情况下,没有简单的方法来更新WordPress主题。 当突然发现流行主题中使用广泛的脚本具有重大漏洞,并且您需要尽快更新主题时,就会变得混乱。 这是一个艰难的选择,因为一方面,如果进行更新,您将丢失所有自定义样式。 另一方面,如果更新速度不够快,您可能会遭受站点被黑的风险。

The core team and the community decided to solve this problem by introducing the concept of parent theme and child theme. A child theme in WordPress would inherit all the functionality, features, and the code of the parent theme without making any changes to the parent theme itself. This allowed users to change the styling of the parent theme and add/modify features without losing the ability to update the parent theme.

核心团队和社区决定通过引入父主题和子主题的概念来解决此问题。 WordPress中的子主题将继承父主题的所有功能,特性和代码,而无需对父主题本身进行任何更改。 这使用户可以更改父主题的样式并添加/修改功能,而不会失去更新父主题的功能。

In theory, any WordPress theme can have child themes however not all WordPress themes are good parent themes. A parent theme with limited functionality and features is not exactly an ideal parent theme candidate in most cases. We will talk about the exceptions later on in the article.

从理论上讲,任何WordPress主题都可以具有子主题,但是并非所有WordPress主题都是好的父主题。 在大多数情况下,功能和功能有限的父主题并不是理想的父主题候选对象。 我们将在文章的后面讨论异常。

A good parent theme also known as theme frameworks usually contains its own action hooks and filters. This allows designers and developers to create a robust custom WordPress site using child themes in a fraction of time.

一个好的父主题(也称为主题框架)通常包含其自己的动作挂钩和过滤器。 这使设计人员和开发人员可以在短时间内使用子主题创建强大的自定义WordPress网站。

人们为什么使用WordPress儿童主题? (Why do people use WordPress Child Themes?)

Designers and developers use child themes to speed up their development. When using a good parent theme, you can drastically reduce the time it takes for you to create a WordPress site. All good parent themes aka theme frameworks offer tons of functionality and customization options, so you don’t have to code everything. DIY users often create child themes to tweak an existing theme without losing the ability to update the parent theme if needed.

设计师和开发人员使用子主题加快开发速度。 使用良好的父主题时,您可以大大减少创建WordPress网站所需的时间。 所有好的父主题(又名主题框架)都提供了大量的功能和自定义选项,因此您不必编写所有代码。 DIY用户经常创建子主题来调整现有主题,而又不会失去根据需要更新父主题的能力。

Creating a WordPress child theme can be as simple as creating a new style.css file in a new folder. All you really need is one line in your new style.css header that defines the template (see the Codex for reference). A robust child theme can have just as many template files as the parent theme if not more. A child theme can have template files that are not even available in the parent theme.

创建WordPress子主题可以像在新文件夹中创建new style.css文件一样简单。 您真正需要的只是定义样式模板的new style.css标头中的一行(请参阅食典参考)。 健壮的子主题可以具有与父主题一样多的模板文件(如果没有更多)。 子主题可以包含父主题中甚至不可用的模板文件。

什么时候应该使用儿童主题? (When Should You Use a Child Theme?)

Decisions

The decision to use a child theme often depends on your needs. Most sites that we build for ourselves and our clients are child themes of the Genesis theme framework. In rare cases when the project is too complex or too simple, then we build it as a standalone custom WordPress theme. As WordPress developers, we need to streamline our workflow while creating quality themes. Creating a child theme of Genesis framework helps us accomplish just that.

使用儿童主题的决定通常取决于您的需求。 我们为自己和客户建立的大多数网站都是Genesis主题框架的子主题。 在极少数情况下,当项目太复杂或太简单时,我们会将其构建为独立的自定义WordPress主题。 作为WordPress开发人员,我们需要在创建高质量主题的同时简化工作流程。 创建Genesis框架的子主题可以帮助我们实现这一目标。

For users we recommend child themes only if you find yourself constantly adding new functions to your theme’s functions.php file and/or constantly adding/modifying the style.css file of your theme. In these cases, we highly recommend that you use a child theme. A short while ago during our WordPress meetup talk, one of the members asked us what if you are only adding custom styles? Is it better to use a child theme or a custom CSS plugin?

对于用户,仅当您发现自己不断向主题的functions.php文件中添加新功能和/或不断添加/修改主题的style.css文件时,才建议使用子主题。 在这些情况下,我们强烈建议您使用子主题。 不久前,在我们的WordPress聚会中,一位成员问我们,如果您仅添加自定义样式,该怎么办? 使用子主题或自定义CSS插件会更好吗?

The answer to that depends on how savvy and comfortable you are with technology. If you are only modifying the styles of a few elements, then using a custom CSS plugin works just fine. However, if you find yourself changing the entire color scheme, moving things around in the CSS, etc, then you definitely should consider using a child theme.

答案取决于您对技术的了解和适应程度。 如果您仅修改一些元素的样式,那么使用自定义CSS插件就可以了。 但是,如果您发现自己更改了整个配色方案,在CSS中移动内容等,那么您绝对应该考虑使用子主题。

Picking a Good Parent Theme is IMPORTANT

选择一个好的父母主题很重要

All WordPress frameworks are parent themes, but not all parent themes are frameworks. We cannot stress this enough. While any WordPress theme can have child themes, not all of them are meant to be used as theme frameworks. We have seen numerous beginners who make the mistakes of creating a child theme of a parent theme that doesn’t offer much functionality.

所有WordPress框架都是父主题,但并非所有父主题都是框架。 我们不能对此施加足够的压力。 尽管任何WordPress主题都可以具有子主题,但并非所有主题都可用作主题框架。 我们已经看到许多初学者,他们在创建功能不多的父主题的子主题时犯了错误。

If you are creating a child theme where you find yourself replacing a lot of the parent theme files, then you should rethink your process. For example you really like the Twenty Eleven theme, and you decided to create a child theme. In your child theme, you had the style.css file, and functions.php file. On top of that, you decided that you don’t like the way the footer looks, so added footer.php. Same for header, etc. If this is the case, then you shouldn’t be using Twenty Eleven as a parent theme. Rather you should be using it as a starter theme that you turn into your own custom theme.

如果要在创建子主题时发现自己替换了许多父主题文件,则应重新考虑您的过程。 例如,您非常喜欢二十一岁主题,并且决定创建一个子主题。 在您的子主题中,您有style.css文件和functions.php文件。 最重要的是,您决定不喜欢页脚的外观,因此添加了footer.php。 标题等也一样。如果是这种情况,那么您不应该使用二十一作为父主题。 相反,您应该将其用作入门主题,然后将其变成自己的自定义主题。

We have had several users who created custom child themes which really should be totally independent custom themes because they had overridden almost all of the parent theme files.

我们有几个用户创建了自定义子主题,这些用户实际上应该是完全独立的自定义主题,因为它们已经覆盖了几乎所有父主题文件。

In short, you should use a child theme when you need the functionality, features, and awesomeness of a powerful parent theme without writing much code for it yourself.

简而言之,当您需要强大的父主题的功能,特性和出色功能时,应该使用子主题,而无需自己为其编写太多代码。

使用WordPress子主题的优点 (Advantages of Using a WordPress Child Theme)

Like most things, there are advantages and disadvantages to using a WordPress Child theme. Let’s take a look at advantages first.

像大多数事物一样,使用WordPress子主题也有其优点和缺点。 首先让我们看一下优势。

1. Safe Updates
A child theme automatically inherits the parent theme’s features, styles, and templates. This allows you to make changes to your site using child themes without ever modifying the parent theme. When a new version of the parent theme arrives, you can safely update it as all your modifications are saved in the child theme.

1.安全更新
子主题会自动继承父主题的功能,样式和模板。 这样,您就可以使用子主题对网站进行更改,而无需修改父主题。 当父主题的新版本到来时,您可以安全地对其进行更新,因为所有修改都保存在子主题中。

2. Easy to Extend

2.易于扩展

A child theme built on a powerful theme framework allows a great deal of flexibility without writing a lot of code. You can selectively modify only the template files and functions that you need without going through other template files. You can add new functionality and much more.

基于强大的主题框架构建的子主题无需编写大量代码即可提供极大的灵活性。 您可以有选择地仅修改所需的模板文件和功能,而无需浏览其他模板文件。 您可以添加新功能等等。

3. Fallback Safe

3.后备安全

When you are creating a complete theme you need to think about all the possible scenarios and code for them. However, when you are working on a child theme and you forget to code for something, then there is always the parent theme’s functionality available as the fallback option.

当您创建一个完整的主题时,您需要考虑所有可能的方案并为其编写代码。 但是,当您处理子主题时,却忘记为某些事情编写代码,那么总会有父主题的功能作为后备选项。

使用儿童主题的缺点 (Disadvantages of Using a Child Theme)

One of the biggest disadvantage of using child themes is the time you need to invest to learn about the parent theme. There is a learning curve specially when you are working with robust frameworks because each of them have their own hooks and filters. You really have to know those to maximize the potential. In our opinion, this learning curve is a one-time thing. For example the first few child themes that you create might take you longer, but after that you will be creating custom websites in a fraction of time. Your overall performance will improve.

使用子主题的最大缺点之一是您需要花费时间来学习父主题。 在使用健壮的框架时,尤其会有一条学习曲线,因为它们每个都有自己的挂钩和过滤器。 您确实必须了解那些才能发挥最大潜力。 我们认为,这种学习曲线是一次性的。 例如,您创建的前几个子主题可能会使您花费更长的时间,但是之后,您将在短时间内创建自定义网站。 您的整体表现将会提高。

Another disadvantage often pointed out is that your parent theme’s developers may loose interest and abandon it, drop a feature that you were using in your child theme, or bring a change that totally destroys your child theme. This is not as bad as it sounds. Mainly because all good WordPress themes are open source and GPL. If the parent theme developer abandons the project, then nothing says that you have to stop using it. Often times, other folks in the community step up to take over the project. If the original theme developers remove a certain feature, then you can simply add it in your child theme. You have the code for it. Lastly, if they make a drastic change that you don’t like, then you can always avoid updating. Theme updates are crucial when there is a security exploit. We always recommend users to update themes because it helps ensure future compatibility with other scripts and plugins.

经常指出的另一个缺点是,父主题的开发人员可能会放弃兴趣并放弃它,放弃在子主题中使用的功能,或者进行更改以完全破坏子主题。 这并不像听起来那样糟糕。 主要是因为所有好的WordPress主题都是开源和GPL。 如果父主题开发人员放弃了该项目,则没有任何事情表明您必须停止使用它。 通常,社区中的其他人会接手该项目。 如果原始主题开发人员删除了某个功能,则只需将其添加到子主题中即可。 您有相应的代码。 最后,如果他们做出了您不希望的大改变,那么您始终可以避免进行更新。 有安全漏洞利用时,主题更新至关重要。 我们始终建议用户更新主题,因为它有助于确保将来与其他脚本和插件兼容。

If you are using a commercial theme framework like Genesis, then you have support option available to help you upgrade your theme or troubleshoot problems. Also a platform like Genesis is not going to just disappear because there is a stable business organization behind it with thousands of customers world wide. For example, they removed certain built-in widgets, but they made them publicly available as plugins for those who still wanted to use it.

如果您正在使用Genesis之类的商业主题框架,则可以使用支持选项来帮助您升级主题或解决问题。 同样,像Genesis这样的平台也不会消失,因为它背后有一个稳定的业务组织,在全球拥有成千上万的客户。 例如,他们删除了某些内置窗口小部件,但是将它们作为插件公开提供给那些仍想使用它的人。

结论 (Conclusion)

It is important to know that even though you can always create a child theme of any WordPress theme, sometimes you may not need a child theme. Think about the number of changes you have planned for your child theme, if the changes you are planning are minor, then you can always create a custom-style.css file in your theme or use a Custom CSS plugin. If the changes are too extreme where you find yourself overriding the core parent theme files, then you probably should be creating a custom theme.

重要的是要知道,即使您始终可以创建任何WordPress主题的子主题,但有时您可能不需要子主题。 考虑一下您为子主题计划的更改数量,如果您计划的更改很小,那么您始终可以在主题中创建custom-style.css文件或使用Custom CSS插件。 如果更改太极端,您会发现自己覆盖了核心父主题文件,那么您可能应该创建一个自定义主题。

We hope that this article helps you understand what is WordPress Child Theme and whether it is a good fit for you or not. If you think we missed something, then please let us know in the comments below.

我们希望本文可以帮助您了解什么是WordPress儿童主题以及它是否适合您。 如果您认为我们错过了某些事情,请在下面的评论中告诉我们。

翻译自: https://www.wpbeginner.com/beginners-guide/wordpress-child-theme-pros-cons/

wordpress主题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值