如何“打包"一个主题 [英] How to "package" a theme

查看:35
本文介绍了如何“打包"一个主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 WP 中打包一个主题?当我说主题时,我指的是所有 HTML、CSS、JS、自定义帖子类型等.

Is there a way to package a theme in WP? When I say theme, I mean all the HTML, CSS, JS, custom post types, etc.

我经常在像 ThemeForest 这样的网站上看到这些东西,在那里他们有一个 WP 主题出售.我想对我已经转换为 HTML/CSS/等的设计做同样的事情.

I see these things often on sites like ThemeForest where they have a WP theme for sale. I'd like to do the same for a design of mine that has already been converted into HTML/CSS/etc.

我只是不熟悉术语,所以我不知道要查找什么.

I'm just not familiar with the terminologies, so I'm not sure what to look up.

推荐答案

对于HTML、CSS、JS:

主题文件(实际上是 PHP、CSS 和 JS)位于您的主题文件夹中.根据模板层次结构,那里的每个 PHP 文件都有自己的角色.CSSJS 文件也存在于主题文件夹中,并使用 wp_register_stylewp_enqueue_style 用于 CSSwp_register_scriptwp_enqueue_script 用于 JS.

The theme files (actually PHP, CSS and JS) are found in your theme folder. Each PHP file there has its own role based on the template hierarchy. CSS and JS files are also present in the theme folder and are called using wp_register_style and wp_enqueue_style for CSS and wp_register_script and wp_enqueue_script for JS.

对于自定义帖子类型:

WordPress 主题文件夹包含一个名为 functions.php 的文件,您可以在其中定义自己用于该主题的函数.您可以向该文件添加 register_post_type 函数以定义您自己的自定义帖子类型.register_post_type 应该与 init 挂钩.取自 WordPress Codex 的示例:

The WordPress theme folder contains a file called functions.php in which you can define your own functions used for that theme. You can add a register_post_type function to that file to define your own custom post types. register_post_type should be hooked to init. Example taken from the WordPress Codex:

function codex_custom_init() {
    $args = array( 'public' => true, 'label' => 'Books' );
    register_post_type( 'book', $args );
}
add_action( 'init', 'codex_custom_init' );

如果您将上述示例添加到您的 functions.php 文件中,您将获得一个名为 Books 的新帖子类型.

If you add the above example to your functions.php file, you will get a new post type called Books.

自定义变量:

如果您想保存站点范围的变量,Options API 允许您add, 更新检索删除这些变量.与 add_menu_page设置 API,您可以在 Dshboard 中创建用户可以管理这些变量的页面.

If you want to save site-wide variables, the Options API allows you to add, update, retrieve and delete those variables. Mixed with add_menu_page and the Settings API, you can create pages in the Dshboard where users can manage these variables.

其他:

同样,您可以添加自定义分类法widgets 到该文件并添加其他 钩子修改WordPress行为以满足您的需求.

Similarly, you can add your custom taxonomies and widgets to that file and also add other hooks to modify WordPress Behaviour to suit your needs.

这篇关于如何“打包"一个主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆