在WordPress中,您将获得默认帖子状态:已发布,草稿和待处理审查。是否可以通过Active主题的function.php文件添加更多帖子类型?

还可以编辑发布元框的名字吗?我提交的内容确实不是出版...

还喜欢添加,我只想在我进行的自定义帖子类型中进行这些更改。

亲切的问候

斯科特

有帮助吗?

解决方案

由于WP 3.0,您可以使用register_post_status()函数()函数( http://hitchhackerguide.com/2011/02/12/register_post_status/ )将新状态添加到帖子类型中。

WP本身使用register_post_status()来注册默认的“发布”,“草稿”等。使用create_initial_post_types()函数在wp-includes/post.php中使用create_initial_post_types()函数 http://hitchhackerguide.com/2011/02/11/create_initial_post_types/ ).

查看这些链接中的代码,您可以了解如何使用该功能。

希望这可以帮助您入门!

其他提示

如果知道如何,可以编写插件。您必须研究文档或类似的插件 http://wordpress.org/extend/plugins/edit-flow/ 或这个 http://wordpress.org/extend/plugins/custom-post-type-ui/

使用“挂钩,操作和过滤器”,您可以更改管理员接口,请参阅此处 http://codex.wordpress.org/plugin_api

到目前为止,我只写了一个简单的插件,我不知道您必须采取的确切步骤来完成这项工作...

祝你好运!

您可以使用register_post_status函数添加自定义帖子状态'。请参阅in create_initial_post_types()in http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/post.php

但是请注意,这并未集成到WordPress后端UI中。

/**
 * PostStatusExtender
 * 
 * @author Hyyan Abo Fakher<hyyanaf@gmail.com>
 */
class PostStatusExtender
{

    /**
     * Extend 
     * 
     * Extend the current status list for the given post type 
     * 
     * @global \WP_POST $post
     * 
     * @param string $postType the post type name , ex: product
     * @param array $states array of states where key is the id(state id) and value
     *                      is the state array 
     */
    public static function extend($postType, $states)
    {

        foreach ($states as $id => $state) {
            register_post_status($id, $state);
        }

        add_action('admin_footer-post.php', function() use($postType, $states) {

            global $post;
            if (!$post || $post->post_type !== $postType) {
                return false;
            }

            foreach ($states as $id => $state) {

                printf(
                        '<script>'
                        . 'jQuery(document).ready(function($){'
                        . '   $("select#post_status").append("<option value=\"%s\" %s>%s</option>");'
                        . '   $("a.save-post-status").on("click",function(e){'
                        . '      e.preventDefault();'
                        . '      var value = $("select#post_status").val();'
                        . '      $("select#post_status").value = value;'
                        . '      $("select#post_status option").removeAttr("selected", true);'
                        . '      $("select#post_status option[value=\'"+value+"\']").attr("selected", true)'
                        . '    });'
                        . '});'
                        . '</script>'
                        , $id
                        , $post->post_status !== $id ? '' : 'selected=\"selected\"'
                        , $state['label']
                );

                if ($post->post_status === $id) {
                    printf(
                            '<script>'
                            . 'jQuery(document).ready(function($){'
                            . '   $(".misc-pub-section #post-status-display").text("%s");'
                            . '});'
                            . '</script>'
                            , $state['label']
                    );
                }
            }
        });


        add_action('admin_footer-edit.php', function() use($states, $postType) {

            global $post;

            if (!$post || $post->post_type !== $postType) {
                return false;
            }

            foreach ($states as $id => $state) {
                printf(
                        '<script>'
                        . 'jQuery(document).ready(function($){'
                        . " $('select[name=\"_status\"]' ).append( '<option value=\"%s\">%s</option>' );"
                        . '});'
                        . '</script>'
                        , $id
                        , $state['label']
                );
            }
        });

        add_filter('display_post_states', function($states, $post) use($states, $postType) {

            foreach ($states as $id => $state) {
                if ($post->post_type == $postType && $post->post_status === $id) {
                    return array($state['label']);
                } else {
                    if (array_key_exists($id, $states)) {
                        unset($states[$id]);
                    }
                }
            }

            return $states;
        }, 10, 2);
    }

}

和这里 如何使用

add_action('init', function() {
    PostStatusExtender::extend(self::NAME, array(
        'sold' => array(
            'label' => __('Sold', 'viasit'),
            'public' => true,
            'exclude_from_search' => true,
            'show_in_admin_all_list' => true,
            'show_in_admin_status_list' => true,
            'label_count' => _n_noop('Sold <span class="count">(%s)</span>', 'Sold <span class="count">(%s)</span>'),
        )
    ));
});

编辑: 修复了代码中的错字。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top