admin管理员组文章数量:1415091
I'm in the midst of reworking a site and in trying to make the backend as friendly as possible I'm trying to avoid hard-coding some of my options in template files. I've got a few archive pages where I'm setting up arrays of data (in my case, a few large lists of categories that are used to alter the display of the template based on what category is being viewed).
At some point I want to expose these options in the backend. I've seen a few ways to do this, including leveraging CPTs, using the settings API, and using an additional db table.
I assume the settings API is the preferred method, but where I've seen other themes use this, it's usually for more global options (site logo, color schemes, etc.) - I'd prefer to somehow expose these options in an area that would make more sense (in the above example, under the categories menu item).
Am I going in the right direction here? I've not been down this road before, most of my themes are basic enough that I've not needed to setup any options.
I'm in the midst of reworking a site and in trying to make the backend as friendly as possible I'm trying to avoid hard-coding some of my options in template files. I've got a few archive pages where I'm setting up arrays of data (in my case, a few large lists of categories that are used to alter the display of the template based on what category is being viewed).
At some point I want to expose these options in the backend. I've seen a few ways to do this, including leveraging CPTs, using the settings API, and using an additional db table.
I assume the settings API is the preferred method, but where I've seen other themes use this, it's usually for more global options (site logo, color schemes, etc.) - I'd prefer to somehow expose these options in an area that would make more sense (in the above example, under the categories menu item).
Am I going in the right direction here? I've not been down this road before, most of my themes are basic enough that I've not needed to setup any options.
Share Improve this question asked Sep 16, 2019 at 7:33 sporkersporker 435 bronze badges 2- What kind of settings are we talking? Could you give some examples? – Krzysiek Dróżdż Commented Sep 16, 2019 at 7:58
- Related: wordpress.stackexchange/questions/97929/… – Matthew Brown aka Lord Matt Commented Sep 16, 2019 at 10:19
1 Answer
Reset to default 1If the options have "visual" impact on the website, consider using the customizer, it gives immediate visual feedback on what changing a value means.
If the settings have no visual impact on the website, then maybe they don't belong in the theme after all, but in a separate plugin.
There are always edge cases, so if the options are really related to categories, and have no visual impact, but you still feel they belong in the theme, then could make sense to put the menu entry close to categories.
But if you have other options, then I would suggest against spread the options in different submenus, because themes can be easily switched, and if you have all theme options in one place it is easy to understand what you loose switching theme. In fact, if you put something in the under the main "Posts" menu, users could easily and rightfully assume that is a core functionality.
本文标签: settings apiWhere to store some pertemplate preferences
版权声明:本文标题:settings api - Where to store some per-template preferences? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745154686a2645096.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论