你更喜欢什么?编写 WordPress 插件或子主题?
当您更喜欢以子主题形式而不是以插件形式编写解决方案时,需要考虑什么?
What think to be consider when you prefer coding a solution in form of child theme rather then in form of a plugin ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
主题和插件解决不同的问题:插件用于业务逻辑,主题用于演示。它们不可互换。我更喜欢使用正确的工具来完成正确的工作。 :)
Themes and plugins solve different problems: plugins are for business logic, themes for presentation. They are not interchangeable. I prefer the right tool for the right job. :)
我更喜欢在子主题(或在 function.php 中),而不是插件的形式。更容易重复使用。您只需将其从一个主题移动到另一个主题即可。
i prefer in child theme (or in function.php), rather then in form of plugin. It's more easy to reuse. You can just move it from one theme to another.
任何通用函数都应该在插件中。这样,它们可用于所有主题,并且如果您在一个位置进行更改,则无需复制并粘贴到多个文件。
子主题的好处是,您可以对现有主题(例如二十主题)进行更改,而无需直接修改源代码,因为源代码很脆弱——可能会导致错误,并且每次更新主题时都必须重复。
Any generic functions should be in a plugin. That way, they are available to all themes, and if you make changes in one place, you don't have to copy and paste to several files.
The benefit of a child theme is that you can make changes to an existing theme, such as twentyten, without directly modifying the source code, which is fragile -- it can cause errors and has to be repeated every time the theme is updated.
视情况而定。如果它可以很容易地被任何(或许多)不同的网站使用,无论主题如何,我都会制作一个插件。
如果它是特定于此特定站点的内容,我可能会将其放在子主题的functions.php 中。即使仅针对某个特定站点,如果我想稍后打开和关闭它,我也可能会将其作为一个插件。
除了可以打开和关闭插件这一事实之外,插件中的代码和functions.php 中的代码之间几乎没有什么区别。
如果它是最容易直接编码到主题中的东西(例如 the_loop 的特定排列),那么当然只需在主题模板中进行并将支持代码放入functions.php中
Depends on the situation. If it's something that could readily be used by any (or many) different sites regardless of the theme, I do a plugin.
If it's something specific to This Particular Site Only, I would probably put it in the child theme's functions.php. Even if specific to the one particular site only, I might make it a plugin if it's something I might want to turn on and off later.
Other than the fact that you can turn plugins on and off, there is little if any difference between code in a plugin and code in functions.php.
If it's something most easily coded straight into the theme (e.g. a particular permutation of the_loop) then of course just do it in the theme template and put supporting code in functions.php