if 中的数组 - 自定义帖子类型 - WordPress 函数.php



我正在使用下面的代码从Wordpress帖子显示和发布元框中为不同的帖子类型剥离零碎的东西。代码都是有效的,我只是想知道它是否可以成功地压缩到一个数组中?我不知道该怎么做。

我将不胜感激任何人能提供的任何帮助。

function hide_publishing_actions(){
        global $post;
        if($post->post_type == 'page'){
            echo '
                <style type="text/css">
                    #misc-publishing-actions,
                    #minor-publishing-actions,
                    ul.subsubsub,
                    p.search-box,
                    div.view-switch,
                    #posts-filter .tablenav select[name=m],
                    #posts-filter .tablenav #post-query-submit{
                        display:none;
                    }
                </style>
            ';
        }
        if($post->post_type == 'post-type-1'){
            echo '
                <style type="text/css">
                    #misc-publishing-actions,
                    #minor-publishing-actions,
                    ul.subsubsub,
                    p.search-box,
                    div.view-switch,
                    #posts-filter .tablenav select[name=m],
                    #posts-filter .tablenav #post-query-submit{
                        display:none;
                    }
                </style>
            ';
        }
        if($post->post_type == 'post-type-2'){
            echo '
                <style type="text/css">
                    #misc-publishing-actions,
                    #minor-publishing-actions,
                    ul.subsubsub,
                    p.search-box,
                    div.view-switch,
                    #posts-filter .tablenav select[name=m],
                    #posts-filter .tablenav #post-query-submit{
                        display:none;
                    }
                </style>
            ';
        }

        if($post->post_type == 'post-type-3'){
            echo '
                <style type="text/css">
                    #misc-publishing-actions,
                    #minor-publishing-actions,
                    ul.subsubsub,
                    p.search-box,
                    div.view-switch,
                    #posts-filter .tablenav select[name=m],
                    #posts-filter .tablenav #post-query-submit{
                        display:none;
                    }
                </style>
            ';
        }        
        if($post->post_type == 'post-type-3'){
            echo '
                <style type="text/css">
                    #misc-publishing-actions,
                    #minor-publishing-actions,
                    ul.subsubsub,
                    p.search-box,
                    div.view-switch,
                    #posts-filter .tablenav select[name=m],
                    #posts-filter .tablenav #post-query-submit{
                        display:none;
                    }
                </style>
            ';
        }        
        if($post->post_type == 'post-type-4'){
            echo '
                <style type="text/css">
                    #misc-publishing-actions,
                    #minor-publishing-actions,
                    ul.subsubsub,
                    p.search-box,
                    div.view-switch,
                    #posts-filter .tablenav select[name=m],
                    #posts-filter .tablenav #post-query-submit{
                        display:none;
                    }
                </style>
            ';
        }        
}
add_action('admin_head-post.php', 'hide_publishing_actions');
add_action('admin_head-post-new.php', 'hide_publishing_actions');
add_action('admin_head-edit.php', 'hide_publishing_actions');

不要分开 if 语句,而是使用 in_array() 组合成一个 if 语句。

请参阅:http://uk1.php.net/in_array

if(in_array($post->post_type, array('page', 'post-type-1', 'post-type-2', 'post-type-3', 'post-type-4')) { ...

最新更新