if - 自定义帖子类型中的数组 - Wordpress functions.php

时间:2014-02-21 11:31:15

标签: php wordpress

我正在使用下面的代码来删除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');

1 个答案:

答案 0 :(得分:0)

使用in_array()组合成一个if语句,而不是单独的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')) { ...