2

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

我经常在 ThemeForest 之类的网站上看到这些东西,那里有 WP 主题可供出售。我想对已经转换为 HTML/CSS/等的我的设计做同样的事情。

我只是不熟悉这些术语,所以我不确定要查找什么。

4

4 回答 4

1

对于HTML, CSS, JS

主题文件(实际上是 PHP、CSS 和 JS)可以在您的主题文件夹中找到。那里的每个 PHP 文件都有基于模板层次结构的自己的角色。CSSJS文件也存在于主题文件夹中,并使用wp_register_styleand wp_enqueue_styleforCSSwp_register_scriptand wp_enqueue_scriptfor调用JS

对于custom post types

WordPress 主题文件夹包含一个名为的文件functions.php,您可以在其中定义用于该主题的自己的函数。您可以register_post_type向该文件添加一个函数来定义您自己的自定义帖子类型。register_post_type应该被迷住了init。取自 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.

自定义变量:

如果您想保存站点范围的变量,选项 API允许您添加更新检索删除这些变量。add_menu_pageSettings API混合使用,您可以在 Dshboard 中创建页面,用户可以在其中管理这些变量。

其他事情:

同样,您可以将自定义分类法小部件添加到该文件,还可以添加其他挂钩来修改 WordPress 行为以满足您的需求。

于 2013-03-06T05:53:49.490 回答
0

我创建了一个 WordPress 样板,用于将现有的 CSS 转换为 WordPress 主题...

http://cferdinandi.github.com/kraken-for-wordpress/

于 2013-03-06T19:20:59.587 回答
0

如果您想将现有的 HTML/CSS 网站转换为 WordPress 主题,您需要做很多事情:

1.将您的样式表重命名为 style.css 并包含一些关于您的主题的元数据:

Theme Name: Twenty Ten
Theme URI: http://wordpress.org/
Description: The 2010 default theme for WordPress.
Author: wordpressdotorg
Author URI: http://wordpress.org/
Version: 1.0
Tags: black, blue, white, two-columns, fixed-width, custom-header, custom-background, threaded-comments, sticky-post, translation-ready, microformats, rtl-language-support, editor-style, custom-menu (optional)

License:
License URI:

General comments (optional).

来源:http ://codex.wordpress.org/Theme_Development#Theme_Stylesheet

您还需要包含 WordPress CSS Core,您可以在此处找到它:http: //codex.wordpress.org/CSS#WordPress_Generated_Classes

2.创建一个 index.php 文件,作为“最后的手段”,如果当前页面没有找到更多特定页面,则使用此模板。有关您可以在此处找到的不同模板的更多信息:http: //codex.wordpress.org/Template_Hierarchy

如果您想为单个页面使用不同的样式,则必须创建一个文件single.php,该文件将用于这些页面。对于包含博客文章的页面,您将使用home.php,... 有关更多文件名,请参见上面的链接。

3.与其将内容直接放在文件中,我们显然在使用 WordPress 时不希望这样做,您必须使用“循环”。您可以在此处阅读更多相关信息:http: //codex.wordpress.org/The_Loop

基本上,它是一个迭代,将遍历页面的所有不同帖子(类别页面和博客主页将拥有比单个页面更多的帖子)。

以下代码对我理解“循环”有很大帮助:

<?php // any code included here occurs before the WordPress loop and is always displayed?    >

<?php if (have_posts()) : ?>

    <?php // if there are posts to display, process any code included here only once ?>
    <?php // display any code output from this region above the entire set of posts ?>

    <?php while (have_posts()) : the_post(); ?>

        <?php // loop through posts and process each according to the code specified here     ?>
        <?php // process any code included in this region before the content of each post     ?>

        <?php the_content(); ?> <?php // this function displays the content of each post ?    >

        <?php // process any code included in this region after the content of each post ?    >

    <?php endwhile; ?>

    <?php // stop the post loop and process any code included here only once ?>
    <?php // any code output will be displayed below the entire set of posts ?>
    
<?php else : ?>

    <?php // if there are no posts to display, process any code that is included here ?>
    <?php // the output of any code included here will be displayed instead of posts ?>

<?php endif; ?>

<?php // any code included here occurs after the WordPress loop and is always displayed ?>

资料来源: http: //perishablepress.com/easy-adaptable-wordpress-loop-templates/

WordPress 主题很难在一篇文章中解释,所以我希望我能帮助你开始,显然,你仍然需要阅读很多关于它的内容,但这很正常,我在 WordPress 函数中查找函数每天参考...所以最后一个链接: http ://codex.wordpress.org/Function_Reference/

祝你好运!

于 2013-03-07T17:28:08.547 回答
0

File structure is going to be variable, correlating to the scope of the project, but there are some industry best practices that you can follow to package your WordPress theme for deployment.

Envato provides extensive documentation on their submission guidelines and addresses formatting standards in a pretty comprehensive manner. Found here: http://support.envato.com/index.php?/Knowledgebase/Article/View/352/0/general-file-preparation-guidelines

Jeffrey Way, of Themeforest, also provides a step-by-step video screencast walkthrough of the file preparation and submission process for Themeforest templates that should serve as a great reference. Found here: http://blog.themeforest.net/site-news/how-to-submit-a-template-to-themeforest-screencast/

Hope this helps.

于 2013-03-06T06:00:15.397 回答